Coder Social home page Coder Social logo

fmotalleb / jalali_date_time_dart Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 109 KB

Jalali DateTime implementation in dartlang identical to dart's DateTime public api

License: MIT License

Dart 100.00%
calendar dart date datetime flutter jalali jalali-date jalali-datetime

jalali_date_time_dart's Introduction

JalaliDateTime

Publish to pub.dev Tests codecov

JalaliDateTime is a Dart package that provides a convenient way to work with Jalali (Persian) dates while using the underlying DateTime structure for time-related methods. This approach is designed to maintain stability and efficiency in your code.

Features

  • Jalali Date Representation: The package allows you to easily represent Jalali dates, including year, month, and day.

  • DateTime Compatibility: Public apis for JalaliDateTime is almost identical to DateTime.

  • Persian DateTime Format: Includes a built-in PersianDateTimeFormat almost identical to DateTimeFormat provided by Intl. You can find more information about the intl package here.

  • Efficient Design: Each Jalali instance seamlessly holds its corresponding DateTime, minimizing overhead and computational load.

  • Stability: For time-related or computation methods such as comparison, subtraction, and more, JalaliDateTime utilizes the DateTime methods, ensuring reliability and accuracy.

  • Super Lightweight: This package maintains a small footprint by relying on just two dependencies: intl and meta.

Installation

To use JalaliDateTime in your Dart project, add it as a dependency in your pubspec.yaml file:

dependencies:
  jalali_date_time: <latest>

Then, run flutter pub get to fetch the package.

Usage

Here's a basic example of how to use JalaliDateTime:

import 'package:jalali_date_time/jalali_date_time.dart';

void main() {
  // Create a JalaliDateTime instance for the current date and time
  final jalaliNow = JalaliDateTime.now();

  // Access Jalali components
  final year = jalaliNow.year;
  final month = jalaliNow.month;
  final day = jalaliNow.day;
  print('today: $year-$month-$day'); // today: 1402-6-27
  // Convert JalaliDateTime to DateTime
  final dateTime = jalaliNow.getDateTime();

  // Perform DateTime operations
  final tomorrow = dateTime.add(const Duration(days: 1));

  // Convert DateTime back to JalaliDateTime
  final jalaliTomorrow = JalaliDateTime.fromDateTime(tomorrow);
  print(jalaliTomorrow == tomorrow.toJalali()); // true
  final tyear = jalaliTomorrow.year;
  final tmonth = jalaliTomorrow.month;
  final tday = jalaliTomorrow.day;
  print('tomorrow: $tyear-$tmonth-$tday'); // tomorrow: 1402-6-28
  // Compare JalaliDateTime objects
  if (jalaliTomorrow.isAfter(jalaliNow)) {
    print('Tomorrow is after today.'); // Tomorrow is after today.
  }
  print(DateTime(1986, 4, 26, 01, 23, 40).toJalali()); // 1365-02-06 01:23:40 +0330

  print(PersianDateTimeFormat.yMMMMEEEEd().format(jalaliTomorrow)); // سه‌شنبه, 1402-شهریور-28 (correct in rtl form)
  print(jalaliTomorrow.toFormat('yMMMMEEEEd') == PersianDateTimeFormat.yMMMMEEEEd().format(jalaliTomorrow)); //true

  print(tomorrow.toFormat('yMMMMEEEEd')); // Thursday, September 19, 2023
  // DateTime
  print(tomorrow.toFormat('yMMMMEEEEd') == DateFormat.yMMMMEEEEd().format(tomorrow)); //true
}

Contribution

Contributions are welcome! If you encounter any issues, have feature requests, or want to contribute code, please feel free to open an issue or create a pull request.

License

This package is distributed under the MIT License. See the LICENSE file for more information.


Note: This package is primarily focused on providing a stable and efficient way to work with Jalali dates. For more detailed documentation and usage examples, refer to the package documentation or visit the GitHub repository.

For additional information on the Jalali calendar, consider referencing external resources and documentation on the Persian calendar system.

jalali_date_time_dart's People

Contributors

fmotalleb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.