Skip to content

Commit

Permalink
fmt: improve str{f,p}time compatibility
Browse files Browse the repository at this point in the history
This adds a whole bunch of conversion specifiers from reading
`man strftime` on my system (GNU libc).

I originally didn't add most of these because they bloat the size of
`BrokenDownTime` and many of them seem a little dubious. But a few folks
have filed issues about compatibility. Given the `strtime` API is
already a complete clusterfuck, it probably makes sense to just match
existing practice as much as we can.

One conversion specifier I intend to add but haven't yet is `%V` for the
ISO 8601 week number. It is conspicuously absent here since `%V` is
currently used for IANA time zone identifiers. That will change in
`jiff 0.2`, which will make room for `%V` to be the ISO 8601 week
number.

Ref #139, Ref #147
  • Loading branch information
BurntSushi committed Jan 21, 2025
1 parent a694986 commit 28fa7b4
Show file tree
Hide file tree
Showing 6 changed files with 1,262 additions and 70 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ result in an error. This change was made to improve compatibility with other
time zone identifiers in `jiff 0.1`, but using them for parsing or formatting
will result in a WARN-level deprecation message.

Enhancements:

* [#147](https://github.com/BurntSushi/jiff/issues/147):
Adds a number of new conversion specifiers to Jiff's `strftime` and
`strptime` APIs. Specifically, `%C`, `%G`, `%g`, `%j`, `%k`, `%l`, `%n`, `%R`,
`%s`, `%t`, `%U`, `%u`, `%W`, `%w`. Their behavior should match the
corresponding specifiers in GNU libc.


0.1.24 (2025-01-16)
===================
Expand Down
8 changes: 2 additions & 6 deletions src/civil/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,8 @@ impl Date {
/// ```
#[inline]
pub fn day_of_year(self) -> i16 {
type DayOfYear = ri16<1, 366>;

let days = C(1) + self.since_days_ranged(self.first_of_year());
DayOfYear::rfrom(days).get()
t::DayOfYear::rfrom(days).get()
}

/// Returns the ordinal day of the year that this date resides in, but
Expand Down Expand Up @@ -3669,9 +3667,7 @@ fn month_add_overflowing(
}

fn day_of_year(year: Year, day: i16) -> Result<Date, Error> {
type DayOfYear = ri16<1, 366>;

let day = DayOfYear::try_new("day-of-year", day)?;
let day = t::DayOfYear::try_new("day-of-year", day)?;
let span = Span::new().days_ranged(day - C(1));
let start = Date::new_ranged(year, C(1), C(1))?;
let end = start.checked_add(span)?;
Expand Down
Loading

0 comments on commit 28fa7b4

Please sign in to comment.