jdate 0.7.0

Dart native js
Flutter Android iOS web

Powerful yet original Dart Jalali date and time for developers.

logo
Powerful yet original Dart Jalali date and time for developers.

CI version issues language licence

Creat a JDate object from DateTime #

DateTime extension toJDate() creates a JDate object for you:

  print(DateTime.now().toJDate());                          // 1399/04/29 16:32:36
  print(DateTime(2020).toJDate());                          // 1398/10/11 00:00:00
  print(DateTime(2020, 7).toJDate());                       // 1399/04/11 00:00:00
  print(DateTime(2020, 7, 16).toJDate());                   // 1399/04/26 00:00:00
  print(DateTime(2020, 7, 16, 12).toJDate());               // 1399/04/26 12:00:00
  print(DateTime(2020, 7, 16, 12, 18).toJDate());           // 1399/04/26 12:18:00
  print(DateTime(2020, 7, 16, 12, 18, 30).toJDate());       // 1399/04/26 12:18:30
  print(DateTime(2020, 7, 16, 12, 18, 30, 450).toJDate());  // 1399/04/26 12:18:30

JDate(year, month, ...) with shamsi date parameters #

You can creates a new jalali date object with a specified shamsi date and time.

    print(JDate.now());                         // 1399/04/29 16:32:36
    print(JDate(1399));                         // 1399/01/01 00:00:00
    print(JDate(1399, 4));                      // 1399/04/01 00:00:00  
    print(JDate(1399, 4, 15));                  // 1399/04/15 00:00:00
    print(JDate(1399, 4, 15, 20));              // 1399/04/15 20:00:00
    print(JDate(1399, 4, 15, 20, 25));          // 1399/04/15 20:25:00
    print(JDate(1399, 4, 15, 20, 25, 30));      // 1399/04/15 20:25:30
    print(JDate(1399, 4, 15, 20, 25, 30, 650)); // 1399/04/15 20:25:30

Other Constructors #

  • JDate.utc(int year, [int month = 1,int day = 1,int hour = 0,int minute = 0,int second = 0,int millisecond = 0,int microsecond = 0 ])
  • JDate.fromDateTime(DateTime date)
  • JDate.fromMicrosecondsSinceEpoch(int microsecondsSinceEpoch, {bool isUtc = false})
  • JDate.fromMillisecondsSinceEpoch(int millisecondsSinceEpoch, {bool isUtc = false})
  • JDate.now()

JDate(...).echo #

    var jd = JDate(2019, 4, 3, 10, 33, 30, 0);
    print(jd.echo('l، d F Y ساعت H:i:s'));      // چهارشنبه، 03 تیر 2019 ساعت 10:33:30
MethodDescriptionRangeExample
aBefore noon and afternoonق.ظ - ب.ظق.ظ
bNumeric representation of a season, without leading zeros0-31
dDay of the month, 2 digits with leading zeros01-3113
fSeason nameبهار-زمستانبهار
g12-hour format of an hour without leading zeros0-1211
h12-hour format of an hour with leading zeros00-1203
iMinutes with leading zeros00-5913
jDay of the month without leading zeros1-314
lA full textual representation of the day of the weekشنبه-جمعهیکشنبه
mNumeric representation of a month, with leading zeros01-1202
nNumeric representation of a month, without leading zeros1-122
sSeconds, with leading zeros00-5903
tNumber of days in the given month0-3128
uMillisecond00000028
vShort year display in lettersیک-نهصد و نود و نهنود و هشت
wNumeric representation of the day of the week0-66
yA two or three digit representation of a year1-99998
ABefore noon and afternoonبعد از ظهر - قبل از ظهرقبل از ظهر
DPersian ordinal suffix for the day of the month, 2 charactersشن‍ - جم‍سه
FA full textual representation of a monthفروردین - اسفنداردیبهشت
G24-hour format of an hour without leading zeros0-243
H24-hour format of an hour with leading zeros00-2403
JDay of the monthیک-سی و یکسیزده
LWhether it’s a leap year0-11
MA short textual representation of a month, two lettersفر-اس‍ار
ODifference to Greenwich time (GMT) in hours-1200 - +1400+0330
VFull year display in lettersصفر-...یک هزار و سیصد و نود و هشت
YA full numeric representation of a year, 4 digits0-...1398

JDate.parse(...) #

You can parse specified shamsi or date from valid date string to convert it to JDate object.

  print(JDate.parse('1399/09/09 13:27:00'));  // 1399/09/09 13:27:00
  print(JDate.parse('1399-09-09 13:27:00'));  // 1399/09/09 13:27:00
  print(JDate.parse('۱۳۹۹/۰۹/۰۹'));           // 1399/09/09 00:00:00
  print(JDate.parse('1399/02/13'));           // 1399/02/13 00:00:00
  print(JDate.parse(JDate(1378).toString())); // 1378/01/01 00:00:00

JDate Parameters #

ParametersDescriptionTypeAccess
microsecondsSinceEpochThe number of microseconds since the 'Unix epoch' 1970-01-01T00:00:00Z (UTC).intread/write
millisecondsSinceEpochThe number of milliseconds since the 'Unix epoch' 1970-01-01T00:00:00Z (UTC).intread/write
microsecondThe microsecond 0...999.intread/write
millisecondThe millisecond 0...999.intread/write
secondThe second 0...59.intread/write
minuteThe minute 0...59.intread/write
hourThe hour of the day, expressed as in a 24-hour clock 0..23.intread/write
dayThe day of the month 1..31.intread/write
monthThe month 1..12.intread/write
yearThe year.intread/write
weekdayThe day of the week 1...7.intread
timeZoneOffsetDifference between local time and UTC.Durationread
timeZoneNameThe time zone name.Stringread
isUtcTrue if this JDate is set to UTC time.boolread
isLeapYearTrue if this JDate.year is a leap year.boolread
weekdayNameReturns the name of weekDay in persian.Stringread
monthNameReturns the name of month in persian.Stringread
shortYearReturns the short version of year.intread
monthLengthReturns number of days in that month.intread

JDate Instance Methods #

MethodDescription
changeTo({int year,int month,...,bool isUtc})Change a JDate instance to specified parameters.
echo(String format)returns String of JDate base on given format.
toString()Returns a human-readable string for this instance.
toDateTime()Converts this JDate to a DateTime object with gregorian date.
add(Duration duration)Returns a new JDate instance with duration added to this.
subtract(Duration duration)Returns a new JDate instance with duration subtracted from this.
isAtSameMomentAs(JDate other)Returns true if this occurs at the same moment as other.
isBefore(JDate other)Returns true if this occurs before other.
isAfter(JDate other)Returns true if this occurs after other.
Duration difference(JDate other)Returns a Duration with the difference when subtracting other from this.
compareTo(JDate other)Compares this JDate object to other, returning zero if the values are equal.
toIso8601String()Returns an ISO-8601 full-precision extended format representation.
toUtc()Returns this JDate value in the UTC time zone.
toLocal()Returns this JDate value in the local time zone.

Static methods #

These methods can be used without creating an instance of the object:

MethodDescription
parse(String string)Parse the string an returns a JDate object, throws Exception if string is not valid
tryParse(String string)Tries to parse the string an returns a JDate object, returns null if string is not valid
jalaliToGregorian(int year, int month, int date)Converts Jalali date to Gregorian and return the result as a BasicDate
gregorianToJalali(int year, int month, int date)Converts Gregorian date to Jalali and return the result as a BasicDate
hijriToGregorian(int year, int month, int date)Converts Hijri date to Gregorian and return the result as a BasicDate
gregorianToHijri(int year, int month, int date)Converts Gregorian date to Hijri and return the result as a BasicDate
jalaliToHijri(int year, int month, int date)Converts Jalali date to Hijri and return the result as a BasicDate
hijriToJalali(int year, int month, int date)Converts Hijri date to Jalali and return the result as a BasicDate

Extension Methods #

These methods can be used on mentioned objects:

MethodDescription
String.numbersToEnglish()Converts Persian digits in string to english digits
String.numbersToPersian()Converts English digits in string to Persian digits
int.toPersianWords(bool ordinal)Returns number as Persian text
DateTime.toJdate()Creates a JDate base on DateTime gregorian date

License #

jdate_dart is available under the BSD 3 Clause license.

The initial version of this library had been written based on JDate.js by Reza Moghaddam.
Date Conversion methods written based on Roozbeh Pournader and Mohammad Toossi work

5
likes
110
pub points
38%
popularity

Publisher

amiralitaheri.ir

Powerful yet original Dart Jalali date and time for developers.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

More

Packages that depend on jdate