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 #147
  • Loading branch information
BurntSushi committed Jan 21, 2025
1 parent 91813d1 commit 0628b59
Show file tree
Hide file tree
Showing 5 changed files with 1,254 additions and 70 deletions.
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 0628b59

Please sign in to comment.