srawlins / timezone

Time zone database and time zone aware DateTime object for Dart.
BSD 2-Clause "Simplified" License
101 stars 52 forks source link

[Bug] Daylight savings starting two hours late #158

Open AndreHaueisen opened 1 year ago

AndreHaueisen commented 1 year ago

In 2023, the US daylight savings start on March 12th at 2 a.m.

Observe the time zone abbreviation in the video. It changes to CDT at 5 a.m. instead of 3 a.m. (since 2 a.m. essentially doesn't exist for the 12th).

https://user-images.githubusercontent.com/13854934/222909465-f6a2902e-3210-44c8-bef9-5f9c77a94305.mp4


This is the code I'm using to get the abbreviation

static String? _getTimeZoneAbbreviation({
    required DateTime dateTime,
    required String? locationName,
  }) {
    if (locationName == null) return null;
    final location = tz.getLocation(locationName);
    final date = tz.TZDateTime.from(dateTime, location);
    return date.timeZone.abbreviation;
  }