ToTransitionDateTime method

DateTime ToTransitionDateTime(
  1. int year
)
Converts this instance to the local wall-clock date and time at which the transition occurs in the specified year (the Dart counterpart of TimeZoneInfo.TransitionTime). The returned value is a UTC DateTime whose components hold the local wall-clock time. The year.

Implementation

DateTime ToTransitionDateTime(int year) {
  DateTime date;

  if (_year == 0) {
    if (_dayOrder < 1 || _dayOrder > 5) {
      throw ArgumentException("The week of the transition must be 1 to 5.");
    }

    final weekday = _EwsToSystemDayOfWeek(_dayOfTheWeek);
    if (_dayOrder == 5) {
      // Last occurrence of the week day in the month.
      date = DateTime.utc(year, _month + 1, 0);
      while (date.weekday != weekday) {
        date = DateTime.utc(date.year, date.month, date.day - 1);
      }
    } else {
      date = DateTime.utc(year, _month, 1);
      while (date.weekday != weekday) {
        date = DateTime.utc(date.year, date.month, date.day + 1);
      }
      date = DateTime.utc(
        date.year,
        date.month,
        date.day + 7 * (_dayOrder - 1),
      );
    }
  } else {
    // TimeZoneInfo doesn't support an actual year. Fixed date transitions occur at the same
    // date every year.
    date = DateTime.utc(year, _month, _dayOrder);
  }

  return date.add(Duration(milliseconds: _timeOfDay.time));
}