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

More chrono padding #4161

Merged
merged 4 commits into from
Sep 18, 2024
Merged

More chrono padding #4161

merged 4 commits into from
Sep 18, 2024

Conversation

KKhanhH
Copy link
Contributor

@KKhanhH KKhanhH commented Sep 14, 2024

Added some padding modifiers for additional presentation types.

Changing the padding modifier for year does kind of break the convention of %C + %y = %Y though. I wanted to also add in century and short year but I wasn't sure how that should be handled.

@vitaut
Copy link
Contributor

vitaut commented Sep 15, 2024

Thanks for the PR but what is the motivation behind this change?

@KKhanhH
Copy link
Contributor Author

KKhanhH commented Sep 15, 2024

I needed a space padded version of the month number and GCC's strftime seems to support the padding modifier for %m (and %j), in addition to the types fmt already supports. %e exists for the day of the month but there's nothing similar for the month number.

As for the year, fmt differs from GCC's strftime in that gcc's always does no padding for %Y, while fmt always does 4 digit padding, so I figured it made sense to add an option that would allow for similar behavior.

@vitaut
Copy link
Contributor

vitaut commented Sep 16, 2024

%j and %m make sense but for %Y we should investigate why there is a discrepancy with strftime.

@KKhanhH
Copy link
Contributor Author

KKhanhH commented Sep 16, 2024

It does seem to differ depending on platform. MSVC's implementation will zero pad the year to 4 digits. %C and %y also technically behaves differently as well. https://godbolt.org/z/T9ssj8fan. Century is never padded, Short year has padding modifiers.

Also I realized that I forgot about %d (which also has GCC padding modifiers), %e will suffice for space padded, but the nonpadded won't exist. Interestingly the zero padding modifier works on %e in GCC.

@vitaut
Copy link
Contributor

vitaut commented Sep 18, 2024

Both Python's str.format and C++ std::format do padding so I think it's fine.

@vitaut vitaut merged commit ed8f8be into fmtlib:master Sep 18, 2024
45 checks passed
@vitaut
Copy link
Contributor

vitaut commented Sep 18, 2024

Merged, thanks!

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 this pull request may close these issues.

2 participants