76 stable releases
new 1.0.75 | Mar 19, 2023 |
---|---|
1.0.68 | Feb 28, 2023 |
1.0.53 | Dec 22, 2022 |
1.0.45 | Nov 29, 2022 |
1.0.4 | Jul 30, 2022 |
#27 in Unix APIs
269 downloads per month
58KB
232 lines
Automatic Timezone Daemon
A Linux daemon to automatically update the system timezone based on location.
How It Works
- The list of timezones and their location is loaded from the
zone1970.tab
file - The current location is retrieved from GeoClue
- The distance between the current location and each timezone is calculated with the Haversine formula
- The shortest distance determines the current timezone set via
systemd-timedated
- Then, the daemon waits for the location updated signal from GeoClue, and repeats from step 2 when it happens
Note: The timezone choice may not be accurate if a reference city in a neighboring timezone is closer than any one in the actual timezone.
Requirements
- GeoClue
- IANA Time Zone Database a.k.a.
tzdata
a.k.a.zoneinfo
- systemd
- The user must be allowed to use the
org.freedesktop.timedate1.set-timezone
action (root
or Polkit rule) - The user must have a running GeoClue agent or the GeoClue configuration must allow the absence of agent with an empty agent
whitelist
(see also Stebalien/localtime - Configuring GeoClue, geoclue/geoclue#74)
Please see the examples/ directory for sample configurations.
Configuration
$ automatic-timezoned --help
Automatically update system timezone based on location
Usage: automatic-timezoned [OPTIONS]
Options:
-z, --zoneinfo-path <ZONEINFO_PATH> Path to zoneinfo tab file [env: AUTOTZD_ZONEINFO_FILE=] [default: /usr/share/zoneinfo/zone1970.tab]
-l, --log-level <LOG_LEVEL> Log level filter. See <https://docs.rs/env_logger> for syntax [env: AUTOTZD_LOG_LEVEL=] [default: info]
-h, --help Print help
-V, --version Print version
Packages
Development
Build
cargo build --release
Test
cargo test
Alternatives
This service depends on the tzdata
package which allows to update the Time Zone Database independently and does not depend on a third-party service to calculate distances,
here are some alternatives which have made different trade-offs for performance and accuracy:
- github.com/Stebalien/localtime: Depends on the unmaintained github.com/bradfitz/latlong Go library.
- Gnome Automatic Time Zone (Source Code): Depends on the
tzdata
package and Nominatim Web API for distances.
License
GNU General Public License v3.0
Dependencies
~14–20MB
~386K SLoC