Gregorian class

Gregorian (Miladi or Milaadi) date class

Date objects are required to be immutable

Dates should be uniquely specified by year, month and day Or by using julian day number

Date objects are valid dates once constructed, It should throw exception when there is a validity or calculation problem

For example constructing date with day being out of month length or date being out of computable region throws DateException

Inheritance

Constructors

Gregorian(int year, [int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, int millisecond = 0])
Create a Gregorian date by using year, month and day
factory
Gregorian.fromDateTime(DateTime dateTime)
Create a Gregorian date by using DateTime object
factory
Gregorian.fromJalali(Jalali date)
Create a Gregorian date from Jalali date
factory
Gregorian.fromJulianDayNumber(int julianDayNumber, [int hour = 0, int minute = 0, int second = 0, int millisecond = 0])
Calculates Gregorian and Julian calendar dates from the Julian Day number julianDayNumber for the period since jdn=-34839655 (i.e. the year -100100 of both calendars) to some millions years ahead of the present.
factory
Gregorian.fromMillisecondsSinceEpoch(int milliseconds, {bool isUtc = false})
Create a Gregorian date from milliseconds since epoch
factory
Gregorian.now()
Get Gregorian date for now
factory

Properties

day int
Gregorian day of the month (1 to 28/29/30/31)
final
formatter GregorianFormatter
Formatter for this date object
no setteroverride
hashCode int
hashcode operator
no setterinherited
hour int
Hour 0..23
final
julianDayNumber int
Julian Day Number
final
millisecond int
Milliseconds 0..999
final
minute int
Minute 0..59
final
month int
Gregorian month (1 to 12)
final
monthLength int
Computes number of days in a given month in a Gregorian year.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
second int
Second 0..59
final
time Duration
Returns the time part as Duration.
no setterinherited
weekDay int
Week day number monday = 1 sunday = 7
no setteroverride
year int
Gregorian year (years BC numbered 0, -1, -2, ...)
final

Methods

add({int years = 0, int months = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0}) Gregorian
makes a new date instance and add days, months and years separately
override
addDays(int days) Gregorian
makes a new date object with added days to this date
override
addMonths(int months) Gregorian
Makes a new date object with added months to this date
override
addYears(int years) Gregorian
Makes a new date object with added years to this date
override
compareTo(Date other) int
Compare dates
inherited
copy({int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond}) Gregorian
Copy this date object with some fields changed
override
distanceFrom(Date other) int
distance between two dates
inherited
distanceTo(Date other) int
distance between two dates
inherited
isLeapYear() bool
Checks if a year is a leap year or not.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDateTime() DateTime
Converts Gregorian date to DateTime object
override
toJalali() Jalali
Converts a Gregorian date to Jalali.
toString() String
Default string representation: Gregorian(year, month, ...). use formatter for custom formatting.
override
toUtcDateTime() DateTime
Converts Gregorian date to DateTime object
override
withDay(int day) Gregorian
Make a new date object with changed day
override
withMonth(int month) Gregorian
Make a new date object with changed month
override
withYear(int year) Gregorian
Make a new date object with changed year
override

Operators

operator +(int days) Gregorian
Add days
override
operator -(int days) Gregorian
Subtract days
override
operator <(Date other) bool
less than operator
inherited
operator <=(Date other) bool
less than or equal operator
inherited
operator ==(Object other) bool
equals operator
inherited
operator >(Date other) bool
bigger than operator
inherited
operator >=(Date other) bool
bigger than or equal operator
inherited
operator ^(Date other) int
distance between two dates
inherited

Constants

max → const Gregorian
Maximum computable Gregorian date
min → const Gregorian
Minimum computable Gregorian date