184 个稳定版本
新 2.0.30 | 2024 年 8 月 15 日 |
---|---|
2.0.26 | 2024 年 7 月 31 日 |
2.0.10 | 2024 年 3 月 25 日 |
1.0.152 | 2024 年 2 月 18 日 |
1.0.4 | 2022 年 7 月 30 日 |
#195 在 Unix API
855 每月下载量
51KB
111 行
自动时区守护进程
一个 Linux 守护进程,根据位置自动更新系统时区。
工作原理
- 从 GeoClue 获取当前位置
- 使用 tzf-rs 确定当前位置的时区
- 通过
systemd-timedated
更新时区 - 然后,守护进程等待 GeoClue 的位置更新信号,并在接收到信号时从步骤 1 重新开始
注意:由于 tzf-rs
使用简化的形状数据,如果非常接近时区边界,时区选择可能不准确。
要求
- GeoClue
- systemd
- 用户必须被允许使用
org.freedesktop.timedate1.set-timezone
动作 (root
或 Polkit 规则) - 用户必须有一个正在运行的 GeoClue 代理,或者 GeoClue 配置必须允许在没有代理的情况下使用,通过空的代理
whitelist
(另请参阅 Stebalien/localtime - 配置 GeoClue,geoclue/geoclue#74)
请参阅 examples/ 目录以获取示例配置。
配置
$ automatic-timezoned --help
Automatically update system timezone based on location
Usage: automatic-timezoned [OPTIONS]
Options:
-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
软件包
开发
构建
cargo build --release
测试
cargo test
替代方案
此服务依赖于 tzf-rs
软件包,该软件包包含时区和它们的地理边界,以下是不同的性能和准确性权衡的替代方案。
- github.com/Stebalien/localtime:依赖于未维护的github.com/bradfitz/latlong Go 库(尽管如果你更喜欢 Go,可以使用github.com/ringsaturn/tzf)。
- Gnome 自动时区(源代码):依赖于
tzdata
包和Nominatim 网络API 进行距离计算。
许可证
GNU 通用公共许可证 v3.0
依赖
~20–31MB
~309K SLoC