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

Get location and/or timezone #10

@FMorschel

Description

@FMorschel

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,
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions