localNow method

DateTime localNow({
  1. int? year,
  2. int? month,
  3. int? day,
  4. int? hour,
  5. int? minute,
  6. int? second,
  7. int? millisecond,
  8. int? microsecond,
  9. bool minuteGranularity = false,
})

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),
  );
}