|
|
|
|
|
by kragen
1681 days ago
|
|
I use GNU date(1) for this: $ TZ=Europe/Warsaw date --date=@1636221900
sáb 06 nov 2021 19:05:00 CET
$ TZ=Europe/Warsaw date --date=2021-11-06T19:05 +%s
1636221900
$ echo $(( ($(TZ=Europe/Riga date +%s --date=2021-11-05T17:00) - $(TZ=America/New_York date +%s --date=2021-12-05T09:00)) / 3600 ))
-719
However, this is super dangerous, because for whatever reason date(1) lies if you give it a nonexistent timezone, pretending that it understands you but actually giving you UTC: $ TZ=Mars date --date=@1636221900
sáb 06 nov 2021 18:05:00 Mars
There's a list of valid timezones that you can conveniently browse with tab-completion after you spend 14 keystrokes to navigate there: $ TZ=/usr/share/zoneinfo/Europe/
Amsterdam Berlin Chisinau Isle_of_Man Lisbon Mariehamn Paris San_Marino Stockholm Vaduz Zagreb
Andorra Bratislava Copenhagen Istanbul Ljubljana Minsk Podgorica Sarajevo Tallinn Vatican Zaporozhye
Astrakhan Brussels Dublin Jersey London Monaco Prague Saratov Tirane Vienna Zurich
Athens Bucharest Gibraltar Kaliningrad Luxembourg Moscow Riga Simferopol Tiraspol Vilnius
Belfast Budapest Guernsey Kiev Madrid Nicosia Rome Skopje Ulyanovsk Volgograd
Belgrade Busingen Helsinki Kirov Malta Oslo Samara Sofia Uzhgorod Warsaw
$ TZ=/usr/share/zoneinfo/Europe/Riga date
dom 07 nov 2021 06:50:44 EET
I wish I had a really good calendar math utility program that handled this sort of thing properly. |
|
Might be a good learning exercise in machine learning: translating natural-language queries from that domain to whatever standard utility.