chronotope / chrono

Date and time library for Rust
Other
3.35k stars 536 forks source link

`std::fmt::Display` implementation of `Weekday` does not honour width, alignment or fill #1620

Closed horazont closed 1 month ago

horazont commented 1 month ago

Summary

The Display implementation of Weekday uses Formatter::write_str, which doesn't honour width or alignment and fill.

Reproducer

use chrono::Weekday;

fn main() {
    println!("Expected result: <{:X>10}>", format!("{}", Weekday::Mon));
    println!("Actual result: <{:X>10}>", Weekday::Mon);
}

(Playground)

Expected result

<XXXXXXXMon>

Actual result

<Mon>

horazont commented 1 month ago

Looking further, seems like the easy way out is to use Formatter::pad instead of write_str.

djc commented 1 month ago

Happy to review a PR for this!

horazont commented 1 month ago

There you go: https://github.com/chronotope/chrono/pull/1621