Skip to content

More chrono padding#4161

Merged
vitaut merged 4 commits intofmtlib:masterfrom
KKhanhH:more_chrono_padding
Sep 18, 2024
Merged

More chrono padding#4161
vitaut merged 4 commits intofmtlib:masterfrom
KKhanhH:more_chrono_padding

Conversation

@KKhanhH
Copy link
Copy Markdown
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.

@KKhanhH KKhanhH force-pushed the more_chrono_padding branch from 9981575 to 91a9100 Compare September 15, 2024 01:24
@vitaut
Copy link
Copy Markdown
Contributor

vitaut commented Sep 15, 2024

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

@KKhanhH
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@vitaut
Copy link
Copy Markdown
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