PersianDate class
An immutable Jalali (Persian) calendar date.
Supports Jalali -61/01/01 to 3177/10/11, which is Gregorian 560-03-20 to 3798-12-31. Every constructor throws ArgumentError outside that range.
- Implemented types
Constructors
- PersianDate(int year, int month, int day)
- Creates a date from a Jalali year, month, and day.
- PersianDate.fromDateTime(DateTime datetime)
-
Creates a date from
datetime, keeping its time of day and time zone.factory - PersianDate.fromGregorian(int year, int month, int day)
-
Creates a date from a Gregorian year, month, and day.
factory
- PersianDate.fromGregorianString(String datetime)
-
Creates a date from an ISO 8601 string, parsed with DateTime.parse.
factory
- PersianDate.fromJson(String json)
-
Creates a date from the
yyyy-MM-ddstring written by toJson.factory - PersianDate.now()
-
Creates a date from the current local date and time.
factory
- PersianDate.withTime(int year, int month, int day, [int hour = 0, int minute = 0, int second = 0])
-
Creates a date from Jalali values with a local time of day.
factory
Properties
- day → int
-
Day of the month, 1 to monthLength.
final
- dayOfYear → int
-
Day of the year, 1 for 1 Farvardin up to daysInYear for the last
day of Esfand.
no setter
- dayPeriod → String
-
Persian name of the part of the day, as CLDR divides it for
fa: نیمهشب from 0:00, بامداد from 1:00, صبح from 4:00, ظهر from 12:00, عصر from 13:00, and شب from 19:00.no setter - daysInYear → int
-
Number of days in year, 365 or 366.
no setter
- firstDayOfMonth → PersianDate
-
First day of this month, date-only.
no setter
- firstDayOfYear → PersianDate
-
First day of this year (1 Farvardin), date-only.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasTime → bool
-
Whether this instance carries a time of day.
no setter
- hour → int
-
Hour of the day, 0 to 23. Throws StateError when hasTime is false.
no setter
- isLeapYear → bool
-
Whether year is a Jalali leap year, with 30 days in Esfand.
no setter
- isToday → bool
-
Whether this date is today in local time.
no setter
- isWeekend → bool
-
Whether this date is a Friday, the weekly holiday in Iran.
no setter
- lastDayOfMonth → PersianDate
-
Last day of this month, date-only.
no setter
- lastDayOfYear → PersianDate
-
Last day of this year (the last day of Esfand), date-only.
no setter
- minute → int
-
Minute of the hour, 0 to 59. Throws StateError when hasTime is
false.
no setter
- month → int
-
Jalali month, 1 (Farvardin) to 12 (Esfand).
final
- monthLength → int
-
Number of days in month of year.
no setter
- monthName → String
-
Persian name of month, for example
فروردینfor month 1.no setter - monthNameDari → String
-
Dari name of month used in Afghanistan, for example
حملfor month 1.no setter - monthNameLatin → String
-
Latin name of month, for example
Farvardinfor month 1.no setter - quarter → int
-
Quarter of the year, 1 to 4: months 1 to 3 are quarter 1.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- season → int
-
Season, 1 (spring) to 4 (winter). The Jalali year starts at the March
equinox, so every season is exactly three months and equals quarter.
no setter
- seasonName → String
-
Persian name of season, for example
بهارfor months 1 to 3.no setter - second → int
-
Second of the minute, 0 to 59. Throws StateError when hasTime is
false.
no setter
- shahanshahiYear → int
-
year in the Shahanshahi (Imperial) numbering, year plus 1180, so
1405 is 2585. See JalaliEra.
no setter
- weekday → int
-
ISO weekday, 1 = Monday to 7 = Sunday, the same as DateTime.weekday.
no setter
- weekdayName → String
-
Persian name of weekday, for example
شنبهfor Saturday.no setter - weekdayNameLatin → String
-
Latin name of weekday, for example
Shanbehfor Saturday.no setter - weekdayNameShort → String
-
One-letter Persian name of weekday, for example
شfor Saturday.no setter - weekdayPersian → int
-
Persian weekday, 1 = Saturday to 7 = Friday.
no setter
- weekOfYear → int
-
Week of the year with Saturday-first weeks, 1 to 54.
no setter
- year → int
-
Jalali year, for example 1403.
final
Methods
-
addDays(
int days) → PersianDate -
Returns the date
daysdays later; negative values go back. -
addMonths(
int months) → PersianDate -
Returns the date
monthsmonths later; negative values go back. -
addYears(
int years) → PersianDate -
Returns the date
yearsyears later; negative values go back. -
compareTo(
PersianDate other) → int -
Orders dates by day; the time of day is ignored.
override
-
copyWith(
{int? year, int? month, int? day}) → PersianDate - Returns a date-only copy with the given fields replaced.
-
daysUntil(
PersianDate end, {bool inclusive = true}) → Iterable< PersianDate> -
Every day from this date to
endin order, date-only. -
differenceInDays(
PersianDate other) → int -
Number of days from
otherto this date, ignoring the time of day. -
differenceInMonths(
PersianDate other) → int -
Number of whole Jalali months from
otherto this date, ignoring the time of day. -
differenceInYears(
PersianDate other) → int -
Number of whole Jalali years from
otherto this date, ignoring the time of day. -
endOfWeek(
) → PersianDate - Friday of this date's Persian week, date-only.
-
format(
String pattern, {bool persianDigits = false, JalaliEra era = JalaliEra.solarHijri}) → String -
Formats this date with
pattern. -
fromNow(
{bool numeric = false, bool persianDigits = false}) → String - This date relative to PersianDate.now, see relativeTo.
-
isAfter(
PersianDate other) → bool -
Whether this date is after
other, ignoring the time of day. -
isBefore(
PersianDate other) → bool -
Whether this date is before
other, ignoring the time of day. -
isSameDay(
PersianDate other) → bool -
Whether this date is the same day as
other; the same as==. -
isSameMonth(
PersianDate other) → bool -
Whether this date is in the same Jalali month and year as
other. -
isSameYear(
PersianDate other) → bool -
Whether this date is in the same Jalali year as
other. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
relativeTo(
PersianDate other, {bool numeric = false, bool persianDigits = false}) → String -
This date relative to
otherin Persian, for exampleدیروز,3 روز پیش, orماه آینده. -
startOfWeek(
) → PersianDate - Saturday of this date's Persian week, date-only.
-
toDateTime(
) → DateTime - Returns the Gregorian DateTime for this date.
-
toHijri(
) → HijriDate - The lunar Hijri date of this day on IranianHijri.official; the same as HijriDate.fromPersianDate.
-
toJson(
) → String -
Returns the date as
yyyy-MM-dd, for JSON and other storage. -
toString(
{bool showDate = true, bool showTime = false, bool showHour = true, bool showMinute = true, bool showSecond = true, bool persianDigits = false, JalaliEra era = JalaliEra.solarHijri}) → String -
Returns the date as
yyyy/MM/dd, optionally followed by the time.override
Operators
-
operator <(
PersianDate other) → bool -
Whether this date is before
other; see compareTo. -
operator <=(
PersianDate other) → bool -
Whether this date is before or the same day as
other. -
operator ==(
Object other) → bool -
Equal when year, month, and day match; the time of day is
ignored.
override
-
operator >(
PersianDate other) → bool -
Whether this date is after
other; see compareTo. -
operator >=(
PersianDate other) → bool -
Whether this date is after or the same day as
other.
Static Properties
- max → PersianDate
-
Last supported date, Jalali 3177/10/11 (Gregorian 3798-12-31).
final
- min → PersianDate
-
First supported date, Jalali -61/01/01 (Gregorian 560-03-20).
final
Static Methods
-
nowruzMoment(
int year) → DateTime -
The moment Jalali
yearbegins, the March equinox (سال تحویل), in UTC. -
parse(
String input, {JalaliEra era = JalaliEra.solarHijri}) → PersianDate -
Parses a Jalali date such as
1403/01/01,1403-1-1, or۱۴۰۳/۰۱/۰۱ ۱۴:۳۰. -
parseFormat(
String input, String pattern, {JalaliEra era = JalaliEra.solarHijri}) → PersianDate -
Parses
inputwritten withpattern, the reverse of format:PersianDate.parseFormat('۴ فروردین ۱۴۰۳', 'd MMMM yyyy')is 1403/01/04. -
tryParse(
String input, {JalaliEra era = JalaliEra.solarHijri}) → PersianDate? - Like parse, but returns null instead of throwing.
-
tryParseFormat(
String input, String pattern, {JalaliEra era = JalaliEra.solarHijri}) → PersianDate? -
Like parseFormat, but returns null instead of throwing
FormatException. Still throws ArgumentError for a
patternthat cannot be parsed.
Constants
-
monthNames
→ const List<
String> - Persian month names, from Farvardin to Esfand.
-
monthNamesDari
→ const List<
String> - Dari month names used in Afghanistan, from Hamal to Hut.
-
monthNamesLatin
→ const List<
String> - Latin transliterations of monthNames, from Farvardin to Esfand.
-
seasonNames
→ const List<
String> - Persian season names, from spring (بهار) to winter (زمستان).
-
weekdayNames
→ const List<
String> - Persian weekday names, indexed by ISO weekday minus one (Monday first).
-
weekdayNamesLatin
→ const List<
String> - Latin transliterations of weekdayNames, indexed by ISO weekday minus one (Monday first).
-
weekdayNamesShort
→ const List<
String> - One-letter Persian weekday names, indexed like weekdayNames (ISO weekday minus one, Monday first): د، س، چ، پ، ج، ش، ی.