isValidDateParts static method
Validates date and time components.
Returns true if all provided components are within valid ranges:
- year: 0-9999
- month: 1-12
- day: 1 to max days in month (requires month to be set)
- hour: 0-23
- minute: 0-59
- second: 0-59
- millisecond: 0-999
- microsecond: 0-999
Components that are null are not validated.
Implementation
static bool isValidDateParts({
int? year,
int? month,
int? day,
int? hour,
int? minute,
int? second,
int? millisecond,
int? microsecond,
}) {
if (year != null && (year < 0 || year > maxYear)) return false;
if (month != null && (month < minMonth || month > maxMonth)) return false;
if (day != null) {
if (month == null) return false;
final int maxDay = monthDayCount(year: year ?? defaultLeapYearCheckYear, month: month);
if (day < 1 || day > maxDay) return false;
}
if (hour != null && (hour < 0 || hour > maxHour)) return false;
if (minute != null && (minute < 0 || minute > maxMinuteOrSecond)) return false;
if (second != null && (second < 0 || second > maxMinuteOrSecond)) return false;
if (millisecond != null && (millisecond < 0 || millisecond > maxMillisecondOrMicrosecond))
return false;
if (microsecond != null && (microsecond < 0 || microsecond > maxMillisecondOrMicrosecond))
return false;
return true;
}