This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Description
Maybe we could introduce something like this? I wanted to create an easier way to detect the current timezone so I could make a clock/countdown app that considers the timezone for alarms and/or countdowns.
Any thoughts on why this should or not be done?
import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;
tz.Location myLocal() {
tz.initializeTimeZones();
final locations = tz.timeZoneDatabase.locations;
final now = DateTime.now();
final currentTimeZoneLocations = locations.values.where((location) {
return location.currentTimeZone.offset == now.timeZoneOffset.inMilliseconds;
});
return currentTimeZoneLocations.singleWhere(
(location) {
final name = location.name == now.timeZoneName;
final abbrev = location.currentTimeZone.abbreviation == now.timeZoneName;
return name || abbrev;
},
orElse: () => currentTimeZoneLocations.first,
);
}