isValidDateParts static method
Returns true if all provided date/time components are within valid
ranges.
Valid ranges for each component:
Components that are null are not validated.
Implementation
@useResult
// All 8 named params are needed to validate each DateTime component
// ignore: avoid_long_parameter_list
static bool isValidDateParts({
int? year,
int? month,
int? day,
int? hour,
int? minute,
int? second,
int? millisecond,
int? microsecond,
}) {
if (!_isInRange(value: year, min: 0, max: DateConstants.maxYear)) {
return false;
}
if (!_isInRange(value: month, min: DateConstants.minMonth, max: DateConstants.maxMonth)) {
return false;
}
if (!_isValidDay(day: day, month: month, year: year)) {
return false;
}
if (!_isInRange(value: hour, min: 0, max: DateConstants.maxHour)) {
return false;
}
if (!_isInRange(value: minute, min: 0, max: DateConstants.maxMinuteOrSecond)) {
return false;
}
if (!_isInRange(value: second, min: 0, max: DateConstants.maxMinuteOrSecond)) {
return false;
}
if (!_isInRange(value: millisecond, min: 0, max: DateConstants.maxMillisecondOrMicrosecond)) {
return false;
}
return _isInRange(value: microsecond, min: 0, max: DateConstants.maxMillisecondOrMicrosecond);
}