jalali_date_time 1.1.4 copy "jalali_date_time: ^1.1.4" to clipboard
jalali_date_time: ^1.1.4 copied to clipboard

JalaliDateTime is a Dart package that provides a convenient way to work with Jalali (Persian) dates while using the underlying DateTime structure.

example/jalali_date_time_example.dart

// ignore_for_file: avoid_print, lines_longer_than_80_chars
import 'package:intl/intl.dart';
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(DateFormat.H().addPattern('m', ':').format(DateTime.now()));
  print(PersianDateTimeFormat.H().addPattern('m').format(JalaliDateTime.now()));
  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
}
1
likes
0
pub points
47%
popularity

Publisher

verified publishermoti.monster

JalaliDateTime is a Dart package that provides a convenient way to work with Jalali (Persian) dates while using the underlying DateTime structure.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

intl, meta

More

Packages that depend on jalali_date_time