isSame method
Implementation
bool isSame(Object? dateTime, String unit) {
DateTime compare = _parse(dateTime);
switch (unit) {
case 'year':
case 'y':
return this.dateTime.year == compare.year;
case 'month':
case 'M':
return this.dateTime.year == compare.year && this.dateTime.month == compare.month;
case 'day':
case 'd':
return this.dateTime.year == compare.year && this.dateTime.month == compare.month && this.dateTime.day == compare.day;
case 'hour':
case 'h':
return this.dateTime.year == compare.year && this.dateTime.month == compare.month && this.dateTime.day == compare.day && this.dateTime.hour == compare.hour;
case 'minute':
case 'm':
return this.dateTime.year == compare.year &&
this.dateTime.month == compare.month &&
this.dateTime.day == compare.day &&
this.dateTime.hour == compare.hour &&
this.dateTime.minute == compare.minute;
case 'second':
case 's':
return this.dateTime.year == compare.year &&
this.dateTime.month == compare.month &&
this.dateTime.day == compare.day &&
this.dateTime.hour == compare.hour &&
this.dateTime.minute == compare.minute &&
this.dateTime.second == compare.second;
case 'millisecond':
case 'ms':
return this.dateTime.millisecondsSinceEpoch == compare.millisecondsSinceEpoch;
default:
return this.dateTime.isAtSameMomentAs(compare);
}
}