round method

  1. @Possible({RangeError})
  2. @useResult
ZonedDateTime round(
  1. TemporalUnit unit,
  2. int value
)

Returns a copy of this rounded to the nearest unit and value.

Contract

Throws RangeError if value <= 0.

Example

final foo = ZonedDateTime('Asia/Singapore', 2023, 4, 15);
foo.round(DateUnit.months, 6); // 2023-06-01T00:00+08:00[Asia/Singapore]

final bar = ZonedDateTime('Asia/Singapore', DateTime2023, 8, 15);
bar.round(DateUnit.months, 6); // 2023-06-01T00:00+08:00[Asia/Singapore]

Implementation

@Possible({RangeError})
@useResult ZonedDateTime round(TemporalUnit unit, int value) => ZonedDateTime._convert(timezone, _native.round(unit, value));