Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot show UNIX epoch with -when 0 #71

Open
jnd-au opened this issue Oct 27, 2024 · 2 comments
Open

Cannot show UNIX epoch with -when 0 #71

jnd-au opened this issue Oct 27, 2024 · 2 comments

Comments

@jnd-au
Copy link
Contributor

jnd-au commented Oct 27, 2024

Currently tz -when 0 will show the current (real) time instead of the UNIX epoch 0. This is a counter-intuitive and unfortunate. It would be good if -when 0 works the same way as -when 1 and -when -1. It would also be nice if ISO 8601/RFC 3339 date-times could be parsed, as this means tz would become quite versatile for developers to see and convert between seconds and timestamps.

@oz
Copy link
Owner

oz commented Oct 28, 2024

  • I think it's fine to fix how -when 0 behave to match the UNIX epoch. 👍🏻
  • But I'd rather not start parsing random formats for now. 👎🏻

If we add support for RFC3339 dates, we're opening the door to many many more human friendly (and non-human friendly) representations too. Like + 1 week, +1d, years, days, or all of go's time durations, and the many incompatible date formats in existence.

Relying on established tools like date works fine.

  • 3 months from now is: tz -when $( date -d '+3 month' +%s ) (or date -v+3m +%s on MacOS/BSD).
  • To use an RFC3339 date: tz -when $( date -d "2024-10-28T15:10:06Z" +%s ), or date -j -f "%Y-%m-%dT%H:%M:%SZ" "2024-10-28T15:10:06Z" +%s on MacOS/BSD (yay).

@jnd-au
Copy link
Contributor Author

jnd-au commented Oct 28, 2024

Okay, but hopefully you will reconsider the latter. ISO 8601 / RFC 3339 are standard and common, not random, and it would be good for tz to support at least one standard, international, platform-independent format. UNIX seconds are a platform-specific notion, and as you noted above, date isn’t even standard between GNU/Linux and BSD. UNIX seconds are especially inconvenient and unintuitive for Windows users, who face multiple steps to use -when with PowerShell e.g. have to convert the time to UTC, then convert to UNIX seconds, then trim the fractional part because tz won’t parse it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants