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

DateTime: Enhancements #323

Open
7 of 17 tasks
sharkdp opened this issue Feb 8, 2024 · 5 comments
Open
7 of 17 tasks

DateTime: Enhancements #323

sharkdp opened this issue Feb 8, 2024 · 5 comments
Labels

Comments

@sharkdp
Copy link
Owner

sharkdp commented Feb 8, 2024

A few enhancements that I thought about while reviewing #287. Let's discuss them here and potentially implement later:

  • "local" should represent the local timezone, not the local UTC offset
  • parse_datetime should work without a UTC offset (and use the local timezone to get the offset)
  • parse_datetime should work for more relaxed input formats. For example, I often want to leave out seconds. I also find the T separator between the date and the time rather unreadable (yes, I know, it's the official standard). https://crates.io/crates/chrono_parser might be useful
  • There should probably be a way to enter dates in another timezone (we can already specify UTC offsets, but not timezones)
  • Documentation
  • Comparison operators like ==, !=, >, etc. should probably work on date times
  • It would be cool to have a shorthand syntax to enter dates. Something like @2024-02-08 or @2024-02-08@ or d"2024-02-08". The latter might allow us to add support for entering other things in the future. The @ syntax might be problematic, as we already use @ for decorators.
  • Displaying of dates should potentially be configurable, or automatically adjusted using localization features. In the US, we might want to show a 12-hour based AM/PM time, in Europe, we might want to show a 24-hour based time. Chrono even has a locale feature (even though it's currently considered unstable), which would allow showing names of months/weekdays in the proper language. We do not have l10n features anywhere else in Numbat, so I'm also okay with skipping that part.
  • Potentially better error messages for things like now() - 1
  • We currently print the UTC offset when showing date times. Personally, I'd rather see the current clock time (e.g. "Central European Time" or "Central European Summer Time", depending on the time of the year) instead.
  • Add accessors for datetime properties, like year, month, day, hour, minute, second, weekday, ordinal. They could be used as conversion functions: now() -> weekday
  • Untangle DateTime and Time/second by introducing a @lang or @register decorator to associate the Time dimension and the second unit with their special role.
  • Resolve other TODOs from original implementation
  • Make TZ environment variable work (it used to, probably broken with the timezone vs offset change)

A few useful functions would be:

  • parse_date (assuming 00:00:00 in the local timezone)
  • Maybe today, which would be the same thing as now(), but with a time of 00:00:00?
  • A two-argument version of parse_datetime that also takes a format string?
@RossSmyth
Copy link
Contributor

Would probably good to take some inspiration from burntshushi's new lib
https://github.com/BurntSushi/jiff

@sharkdp
Copy link
Owner Author

sharkdp commented Jul 24, 2024

Would probably good to take some inspiration from burntshushi's new lib

Yes! I thought the same thing when I read about it. Would be interesting to port from chrono to jiff as a small experiment. jiff might be beneficial for us due to its TZ database handling strategy, which would solve #344 after all.

@BurntSushi
Copy link

Would be interesting to port from chrono to jiff as a small experiment.

I'm doing some of these myself and adding APIs to Jiff as a result of those experiments. So if you do this, please reach out. I'd love to hear feedback. I'm keen to iterate for the next ~year and get Jiff to 1.0.

@BurntSushi
Copy link

Looking at your list, I believe Jiff should support doing everything there, except for automatic locale support. For locale, I'm hoping an integration with icu will make that work, although I haven't done any exploration there.

@sharkdp
Copy link
Owner Author

sharkdp commented Jul 28, 2024

@BurntSushi I ported Numbat from chrono to jiff here: #511

I wrote some comments, which might be helpful for you to get some insights into the chrono-to-jiff journey by someone who's not yet familar with jiff.

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

No branches or pull requests

3 participants