operator + method

  1. @useResult
DateTime operator +(
  1. Period period
)

Returns a copy of this with the period added.

This function adds the conceptual units of time unlike add.

// DST occurs at 2023-03-12 02:00
// https://www.timeanddate.com/time/change/usa/detroit?year=2023

// Assume the current timezone is `America/Detroit`.
final foo = DateTime(2023, 3, 12);

foo + Period(days: 1);      // 2023-03-13 00:00
foo.add(Duration(days: 1)); // 2023-03-13 01:00

Implementation

@useResult DateTime operator + (Period period) => copyWith(
  year: year + period.years,
  month: month + period.months,
  day: day + period.days,
  hour: hour + period.hours,
  minute: minute + period.minutes,
  second: second + period.seconds,
  millisecond: millisecond + period.milliseconds,
  microsecond: microsecond + period.microseconds,
);