Open cardil opened 2 years ago
The sunriset library looks like a good candidate to easily implement this. Here's example code:
You can also get current location automatically from timedatectl
:
# timedatectl
Local time: Mon 2021-10-25 16:14:37 CEST
Universal time: Mon 2021-10-25 14:14:37 UTC
RTC time: Mon 2021-10-25 14:14:37
Time zone: Europe/Warsaw (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
For most people, the day/night transitions shifts during the year. It would be nice to be able to resolve them automatically from given geolocation.
I image the UI could be extended to have a checkbox titled: "Use geolocation to resolve Day/Night time". When checked, fields for latitude and longitude could have appeared. When fields are filled, Day/Night time is automatically resolved.
Such feature is for example implemented in DarkReader extension:
https://github.com/darkreader/darkreader/blob/90bb1f0c4ae7e915e547bf2bdc603e725326c1b0/src/utils/time.ts#L228-L251