copyWith method
Returns a new DateTime with the provided fields replaced.
If isUtc is provided, the returned value will be constructed in UTC
or local time accordingly. Otherwise, it preserves the current timezone.
Implementation
DateTime copyWith({
int? year,
int? month,
int? day,
int? hour,
int? minute,
int? second,
int? millisecond,
int? microsecond,
bool? isUtc,
}) {
final useUtc = isUtc ?? this.isUtc;
if (useUtc) {
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,
);
}
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,
);
}