mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
40 lines
998 B
Dart
40 lines
998 B
Dart
extension DateTimeExtension on DateTime {
|
|
DateTime copyWith({
|
|
int? year,
|
|
int? month,
|
|
int? day,
|
|
int? hour,
|
|
int? minute,
|
|
int? second,
|
|
int? millisecond,
|
|
int? microsecond,
|
|
}) {
|
|
if (isUtc) {
|
|
return DateTime.utc(
|
|
year ?? this.year,
|
|
month ?? this.month,
|
|
day ?? this.day,
|
|
hour ?? this.hour,
|
|
minute ?? this.minute,
|
|
second ?? this.second,
|
|
millisecond ?? this.millisecond,
|
|
microsecond ?? this.microsecond,
|
|
);
|
|
} else {
|
|
return DateTime(
|
|
year ?? this.year,
|
|
month ?? this.month,
|
|
day ?? this.day,
|
|
hour ?? this.hour,
|
|
minute ?? this.minute,
|
|
second ?? this.second,
|
|
millisecond ?? this.millisecond,
|
|
microsecond ?? this.microsecond,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Return a new object representing the midnight of the same day
|
|
DateTime toMidnight() =>
|
|
copyWith(hour: 0, minute: 0, second: 0, millisecond: 0, microsecond: 0);
|
|
}
|