BurntSushi / jiff

A date-time library for Rust that encourages you to jump into the pit of success.
The Unlicense
1.72k stars 29 forks source link

please consider adding additional format specifiers to jiff::fmt::strtime for strptime, strftime #139

Open fdncred opened 1 week ago

fdncred commented 1 week ago

The notable missing format specifiers from chrono, that I use pretty frequently, are:

spec example description
%c Sun Jul 8 00:34:60 2001 Locale’s date and time (e.g., Thu Mar 3 23:05:25 2005).
%+ 2001-07-08T00:34:60.026490+09:30 ISO 8601 / RFC 3339 date & time format. 

They're really just convenience formatters, but they're pretty convenient. 😄

BurntSushi commented 1 week ago

%c is probably a no-go if its specification is "the default format for the current locale." Jiff is very intentionally locale-unaware. I'm not sure if Chrono is even doing the right thing there. It would be better to use icu for that.

I am unsure about %+ because I'm not sure I want to encourage that format over RFC 9557 more than it already is. Moreover, it's unclear to me why you would use that when a Timestamp's default Display impl is exactly that: RFC 3339.

fdncred commented 1 week ago

Moreover, it's unclear to me why...

Because I'm writing a nushell command to format dates where dt format <specifier> allows user to print the datetime in the format they specify and, it's more convenient to have specifiers that print the datetime with 2 characters rather than 10, or however many it would take. I can, of course, hard code custom specifiers and parse them in my code if you're not willing to add these.

BurntSushi commented 1 week ago

I'll noodle on that, but I think there may be an impedance mismatch here. The needs of a strtime DSL at the library level are likely somewhat different than the needs at a user facing CLI level. I'm still unsure of this because I want to be very careful about encouraging more offset-only formatting.