Skip to content

Fix width and alignment for calendar types - #4935

Merged
vitaut merged 1 commit into
fmtlib:mainfrom
IfkumRfnl:investigate/calendar-padding
Sep 11, 2026
Merged

vitaut merged 1 commit into
fmtlib:mainfrom
IfkumRfnl:investigate/calendar-padding

Conversation

@IfkumRfnl

Copy link
Copy Markdown
Contributor

Summary

Calendar formatters used a full timestamp when the format specified only width or alignment. For example, fmt::format("{:5}", fmt::day(5)) returned 1900-01-05 00:00:00. Formatting a year with width caused an assertion failure.

Set the default format for each calendar type before parsing. This keeps the calendar output when width or alignment is specified.

Added regression tests for all five calendar types, including fill, dynamic width, explicit chrono formats, and localization. The C++17 chrono and wide-character test suites pass.

@IfkumRfnl
IfkumRfnl marked this pull request as ready for review September 7, 2026 06:54
@IfkumRfnl
IfkumRfnl requested a review from vitaut as a code owner September 7, 2026 06:54
@vitaut
vitaut merged commit 2012961 into fmtlib:main Sep 11, 2026
47 checks passed
@vitaut

vitaut commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix!

nebkat added a commit to nebkat/fmt that referenced this pull request Sep 13, 2026
tm_writer takes a locale_ref and the localized flag instead of a std::locale
reference, and resolves the locale the same way numeric {:L} does: classic
unless localized, otherwise the one passed to the formatting function or the
global one. The facet calls are confined to three shims, so with locale
support disabled nothing pulls in std::locale. get_locale, which existed only
to materialize and own a std::locale, is no longer needed.

The std::tm formatter treated a missing locale argument as the classic locale
rather than the global one, and since fmtlib#4935 routes {:L} on weekday and month
through it, {:L} without a locale argument ignored the global locale for all
calendar types. It now uses the global locale, as numeric {:L} does. Output
with an explicit locale is unchanged. With FMT_USE_LOCALE=0, {:L} no longer
consults the global locale, matching numeric formatting under that option. An
-Os test program loses all 16 of its std::locale and time_put symbols.
nebkat added a commit to nebkat/fmt that referenced this pull request Sep 16, 2026
tm_writer takes a locale_ref and the localized flag instead of a std::locale
reference, and resolves the locale the same way numeric {:L} does: classic
unless localized, otherwise the one passed to the formatting function or the
global one. The facet calls are confined to three shims, so with locale
support disabled nothing pulls in std::locale. get_locale, which existed only
to materialize and own a std::locale, is no longer needed.

The std::tm formatter treated a missing locale argument as the classic locale
rather than the global one, and since fmtlib#4935 routes {:L} on weekday and month
through it, {:L} without a locale argument ignored the global locale for all
calendar types. It now uses the global locale, as numeric {:L} does. Output
with an explicit locale is unchanged. With FMT_USE_LOCALE=0, {:L} no longer
consults the global locale, matching numeric formatting under that option. An
-Os test program loses all 16 of its std::locale and time_put symbols.
vitaut pushed a commit that referenced this pull request Sep 16, 2026
tm_writer takes a locale_ref and the localized flag instead of a std::locale
reference, and resolves the locale the same way numeric {:L} does: classic
unless localized, otherwise the one passed to the formatting function or the
global one. The facet calls are confined to three shims, so with locale
support disabled nothing pulls in std::locale. get_locale, which existed only
to materialize and own a std::locale, is no longer needed.

The std::tm formatter treated a missing locale argument as the classic locale
rather than the global one, and since #4935 routes {:L} on weekday and month
through it, {:L} without a locale argument ignored the global locale for all
calendar types. It now uses the global locale, as numeric {:L} does. Output
with an explicit locale is unchanged. With FMT_USE_LOCALE=0, {:L} no longer
consults the global locale, matching numeric formatting under that option. An
-Os test program loses all 16 of its std::locale and time_put symbols.
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