Repository: chronotope/chrono (language: rust)

Issue:
`std::fmt::Display` implementation of `Weekday` does not honour width, alignment or fill
## Summary

The `Display` implementation of `Weekday` uses `Formatter::write_str`, which doesn't honour [width](https://doc.rust-lang.org/std/fmt/index.html#width) or [alignment and fill](https://doc.rust-lang.org/std/fmt/index.html#fillalignment).

## Reproducer

```rust
use chrono::Weekday;

fn main() {
    println!("Expected result: <{:X>10}>", format!("{}", Weekday::Mon));
    println!("Actual result: <{:X>10}>", Weekday::Mon);
}
```

([Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e9d6cafc549ad505e6f932697fbda305))

## Expected result

`<XXXXXXXMon>`

## Actual result

`<Mon>`


Discussion / hints:
Looking further, seems like the easy way out is to use [`Formatter::pad`](https://doc.rust-lang.org/std/fmt/struct.Formatter.html#method.pad) instead of `write_str`.
Happy to review a PR for this!

Fix patch:
diff --git a/src/weekday.rs b/src/weekday.rs
index f41b5845cf..5c62ea3ed9 100644
--- a/src/weekday.rs
+++ b/src/weekday.rs
@@ -171,7 +171,7 @@ impl Weekday {
 
 impl fmt::Display for Weekday {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.write_str(match *self {
+        f.pad(match *self {
             Weekday::Mon => "Mon",
             Weekday::Tue => "Tue",
             Weekday::Wed => "Wed",
@@ -331,6 +331,16 @@ mod tests {
         }
     }
 
+    #[test]
+    fn test_formatting_alignment() {
+        // No exhaustive testing here as we just delegate the
+        // implementation to Formatter::pad. Just some basic smoke
+        // testing to ensure that it's in fact being done.
+        assert_eq!(format!("{:x>7}", Weekday::Mon), "xxxxMon");
+        assert_eq!(format!("{:^7}", Weekday::Mon), "  Mon  ");
+        assert_eq!(format!("{:Z<7}", Weekday::Mon), "MonZZZZ");
+    }
+
     #[test]
     #[cfg(feature = "serde")]
     fn test_serde_serialize() {


Test patch: