PersianDate.withTime constructor
Creates a date from Jalali values with a local time of day.
The date is validated like PersianDate.new. Throws ArgumentError
when hour is outside 0 to 23, or minute or second is outside
0 to 59, and when that wall-clock time does not exist in the local
time zone because of a daylight saving change. The result carries a
local DateTime, so hasTime is true and toDateTime returns that
moment.
Implementation
factory PersianDate.withTime(
int year,
int month,
int day, [
int hour = 0,
int minute = 0,
int second = 0,
]) {
final date = PersianDate(year, month, day);
if (hour < 0 || hour > 23) {
throw ArgumentError.value(hour, 'hour', 'Must be in 0 to 23');
}
if (minute < 0 || minute > 59) {
throw ArgumentError.value(minute, 'minute', 'Must be in 0 to 59');
}
if (second < 0 || second > 59) {
throw ArgumentError.value(second, 'second', 'Must be in 0 to 59');
}
final g = d2g(date._julianDay);
final dateTime = DateTime(g.gy, g.gm, g.gd, hour, minute, second);
if (dateTime.day != g.gd ||
dateTime.hour != hour ||
dateTime.minute != minute) {
throw ArgumentError(
'$date $hour:$minute does not exist in the local time zone',
);
}
return PersianDate._(year, month, day, dateTime);
}