ILibTimeZone constructor
Create a zone for the IANA id (e.g. 'Europe/Paris'), or the special id
'local' for the system zone. Unknown ids fall back to 'Etc/UTC'.
allZoneData overrides the bundled zoneinfo table; it defaults to the
data for the current locale.
Implementation
ILibTimeZone(String id, [Map<String, dynamic>? allZoneData]) : _id = id {
if (_id == 'local') {
// System time zone: sample the OS DST-aware offsets via core DateTime.
// No zoneinfo is loaded; _zone stays null and all offsets come from the
// platform. getId() remains 'local'.
_isLocal = true;
final int year = sampleYear();
_offsetJan1 = sysWallOffsetMinutes(year, 1, 1, 0, 0);
_offsetJun1 = sysWallOffsetMinutes(year, 6, 1, 0, 0);
// Standard offset is the one closest to -inf (min); DST savings is the spread.
_offset = _offsetJan1 < _offsetJun1 ? _offsetJan1 : _offsetJun1;
_dstSavings = (_offsetJan1 - _offsetJun1).abs();
return;
}
allZoneData ??= _getZoneData();
final Object? entry = allZoneData[_id];
if (entry is String) {
_zone = allZoneData[entry] as Map<String, dynamic>?;
} else if (entry is Map<String, dynamic>) {
_zone = entry;
} else {
// Unknown zone id: fall back to Etc/UTC, including its id (getId() returns
// "Etc/UTC" for an unrecognized zone).
_zone = allZoneData['Etc/UTC'] as Map<String, dynamic>?;
_id = 'Etc/UTC';
}
if (_zone != null) {
_offset = _parseOffset(_zone!['o'] as String? ?? '0:0');
if (_zone!.containsKey('s') && _zone!.containsKey('e')) {
final Map<String, dynamic> s = _zone!['s'] as Map<String, dynamic>;
_dstSavings = _parseOffsetMinutes(s['v'] as String? ?? '1:0');
}
}
}