Hacker News new | ask | show | jobs
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.
1 comments

> I wish I had a really good calendar math utility

Might be a good learning exercise in machine learning: translating natural-language queries from that domain to whatever standard utility.

Maybe, and it wouldn't have to be as slow and unresponsive as Wolfram Vertical Line Alpha or obscure your answers as an attempt to upsell you, but I think it would still tend to have the same kinds of essential usability problems: a gulf of execution in figuring out how to phrase a query so the system would understand it, and a gulf of evaluation in figuring out whether the calculation it had carried out was the calculation you wanted.