Gregorian constructor
Create a Gregorian date by using year
, month
and day
year and month default to 1
Implementation
Gregorian(this.year,
[this.month = 1,
this.day = 1,
this.hour = 0,
this.minute = 0,
this.second = 0]) {
// should be between: Gregorian(560,3,20) and Gregorian(3798,12,31)
if (year < 560 || year > 3798) {
throw DateException('Gregorian date is out of computable range.');
}
if (month < 1 || month > 12) {
throw DateException('Gregorian month is out of valid range.');
}
// monthLength is very cheap
// isLeapYear is also very cheap
final ml = monthLength;
if (day < 1 || day > ml) {
throw DateException('Gregorian day is out of valid range.');
}
// no need for further analysis for MAX, but for MIN being in year 560:
if (year == 560) {
if (month < 3 || (month == 3 && day < 20)) {
throw DateException('Gregorian date is out of computable range.');
}
}
}