Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
horazont opened this issue Oct 13, 2024 · 3 comments · Fixed by #1621
Closed

Comments

@horazont
Copy link
Contributor

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
Copy link
Contributor Author

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

@djc
Copy link
Member

djc commented Oct 14, 2024

Happy to review a PR for this!

horazont added a commit to horazont/chrono that referenced this issue Oct 14, 2024
That way, width, alignment and fill from the format string are
respected.

Fixes chronotope#1620.
@horazont
Copy link
Contributor Author

There you go: #1621

@djc djc closed this as completed in #1621 Oct 14, 2024
@djc djc closed this as completed in 771c047 Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants