tiffany352 / rink-rs

Unit conversion tool and library written in rust
https://rinkcalc.app/about
GNU General Public License v3.0
408 stars 28 forks source link

Make "now" respect system timezone #101

Closed deviant closed 2 years ago

deviant commented 2 years ago

Most users probably want to manipulate time relative to the present in their local timezone. This brings rink's functionality closer to similar tools.

In date(1):

> date -d 'now + 1 hour'
Fri 23 Jul 09:54:02 CEST 2021

Before:

> now
2021-07-23 06:54:05.699222874 +00:00 (now)
> now + 1 hour
2021-07-23 07:54:10.940110380 +00:00 (in an hour)

After:

> now
2021-07-23 08:54:13.219044877 +02:00 (now)
> now + 1 hour
2021-07-23 09:54:15.555096329 +02:00 (in an hour)
deviant commented 2 years ago

It would be nicer yet if this printed the timezone name instead of a numerical offset, but I don't know how to do that easily with chrono and I'm fairly new to Rust. :)

deviant commented 2 years ago

I took a peek at that but it seems to only hold timezone identifiers. To do this properly, it would require code that looks at the TZ environment variable, and failing that, /etc/localtime. I don't know if there's a crate that has this functionality already, but there is an issue for this in chrono-tz. Feel free to merge as-is, though!