localNow method
Returns the current date and time in the local timezone.
Set minuteGranularity to true to return the current date and time with
minute granularity. If set, you cannot specify a value for second,
millisecond or microsecond.
Implementation
DateTime localNow({
int? year,
int? month,
int? day,
int? hour,
int? minute,
int? second,
int? millisecond,
int? microsecond,
bool minuteGranularity = false,
}) {
assert(
minuteGranularity == false ||
(second == null && millisecond == null && microsecond == null),
'minuteGranularity is only allowed if second, millisecond and microsecond are null',
);
final now = mockNowUTC != null
? utcToLocal(mockNowUTC!)
: TZDateTime.now(local);
return TZDateTime.local(
year ?? now.year,
month ?? now.month,
day ?? now.day,
hour ?? now.hour,
minute ?? now.minute,
minuteGranularity ? 0 : (second ?? now.second),
minuteGranularity ? 0 : (millisecond ?? now.millisecond),
minuteGranularity ? 0 : (microsecond ?? now.microsecond),
);
}