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] Incorrect DST transition #164

Closed Pante closed 3 months ago

Pante commented 1 year ago

The following code snippet on master:

import 'package:timezone/data/latest.dart' as tz;

void main() {
  tz.initializeTimeZones();

  final location = getLocation('America/Detroit');
  final datetime = TZDateTime(location, 2023, 3, 12, 2);

  print('local: ${datetime.toIso8601String()}');
  print(datetime.millisecondsSinceEpoch);
}

Produces the following:

local: 2022-03-13T01:00:00.000-0500
1647151200000

This is incorrect since the time should 3am instead of 1am due to DST, https://www.timeanddate.com/time/change/usa/detroit?year=2023.

From a brief look it's probably related to how the timezone is derived in https://github.com/srawlins/timezone/blob/master/lib/src/date_time.dart#L22.