141 Commits

Author SHA1 Message Date
Victor Zverovich
a9e41a6df2 Rename rep to abs_rep in duration_formatter and simplify the tests
The old name differed from Rep only in case, which made the narrowing
fixed in #5003 easy to miss.
2026-11-07 15:42:47 -08:00
khan
47fcd357ab
Avoid narrowing duration day counts to the original representation (#5003)
* Avoid narrowing duration day counts to the original representation

* Keep duration field values in the promoted representation

---------

Co-authored-by: Aikhan Jumashukurov <117706338+aikhanj@users.noreply.github.com>
2026-11-06 15:44:43 -08:00
Victor Zverovich
7690aa5574 Simplify float to integral duration_cast and its tests
Compute the upper bound as 2^digits with std::ldexp instead of
static_cast<FromRep>(max) + 1, which is only exact when rounding to
nearest: with FE_UPWARD in an unoptimized build the bound became
2^63 + 2048 and a count of 2^63 reached the undefined conversion.
Truncate the count once and use it for both the check and the cast.

Skip the checks that need safe duration casts when
FMT_SAFE_DURATION_CAST is 0, where the NaN time point check failed.
Drop the 1e300 time point and two bool assertions, which don't catch
anything the others don't, and test max + 1 and NaN directly.
2026-11-06 09:43:42 -08:00
aizu-m
4ed3535092
Fix unchecked float to integral conversion in detail::duration_cast (#4985)
* fix unchecked float to integral conversion in detail::duration_cast

* Check the truncated count in float to integral duration_cast

* Keep the duration_cast fallback for custom representations

* Use an explicit rep in the custom_rep duration_cast test

std::chrono::seconds is duration<long> on 64-bit Linux so common_type<long,
custom_rep> had no specialization and chrono-test failed to compile there.

* Exclude bool from the checked float to integral duration_cast
2026-11-01 09:10:37 -08:00
Victor Zverovich
dc4675a400 Simplify floating-point 12-hour test 2026-10-31 08:38:20 -07:00
Nathan Chandrasekar
92d2c541e3
Fix 12-hour formatting of floating-point durations (#4988) 2026-10-31 08:27:00 -07:00
Victor Zverovich
97bd2ad530 Simplify ISO week computation
Compute the ISO week-based year and week number from the day of the year
of the Thursday in the current week instead of the weekday of December 31.
This only needs a leap year check, which works for negative years without
floored division, and is about 3 times faster.

For std::tm values with tm_wday and tm_yday inconsistent with tm_year,
%G, %g and %V now give the same results as strftime.

Replace the negative year tests with a year_month_day test that also
covers the leap year check and days_from_civil for negative years.
2026-10-30 11:53:17 -07:00
Victor Zverovich
f87a75e152 Clean up duration_formatter and simplify duration sign tests 2026-10-25 09:34:12 -07:00
Mohith
434e30f81f
Fix signs in floating-point duration formatting (#4981) 2026-10-24 10:28:23 -07:00
DeviousCardi
011e5a911f
Fix ISO week number and year for negative years (#4989)
iso_year_weeks computed the weekday of December 31 with truncating
division and a remainder that is negative for negative years, so it
returned the wrong number of ISO weeks for years before year 0. As a
result %V and %G/%g were wrong around the start and end of such years,
e.g. 1 January of year -1 was formatted as week 52 of year -2 instead
of week 53, and 31 December of year -2 as week 1 of year -1.

Use floored division and a non-negative remainder.


Claude-Session: https://claude.ai/code/session_01Y1b55sEL1gA1c3FCMcQCbm

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-24 09:59:35 -07:00
fhgffy
0fc31633e7
Fix weekday and day of year when formatting year_month_day (#4978)
The year_month_day formatter only filled in tm_year, tm_mon and tm_mday,
so specifiers that depend on the weekday or the day of the year (%a, %A,
%u, %w, %j, %U, %W, %V, %G, %g) were formatted from zero-initialized
fields, e.g. every date was printed as a Sunday. Compute tm_wday and
tm_yday from the date before passing it to the tm formatter.
2026-10-18 07:14:35 -07:00
Victor Zverovich
4ded41f186 Simplify pre-epoch local_time formatting
Floor the seconds before calling gmtime instead of adjusting tm_sec, and
keep the subsecond remainder in the common duration type, which fixes
overflow for narrow reps such as duration<int16_t, std::micro>.
2026-10-18 07:02:27 -07:00
Kartikey Negi
6ba294f5a6
Fix subsecond formatting for pre-epoch local_time (#4975) (#4976) 2026-10-18 06:45:15 -07:00
Nebojša Cvetković
e4751cc709
Don't require std::locale in chrono.h when FMT_USE_LOCALE is 0 (#4921)
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.
2026-09-16 08:37:57 -07:00
Victor Zverovich
1da57c78d4 Simplify calendar_padding test 2026-09-11 08:31:42 -07:00
IfkumRfnl
2012961e3e
Fix width and alignment for calendar types (#4935) 2026-09-11 08:22:02 -07:00
aizu-m
de4c6c502e
fix out-of-range float to int conversion in to_nonnegative_int (#4802) 2026-06-16 23:14:58 -07:00
Jiami Lin
a90ad5d6fd
Fix formatting std::tm with null tm_zone (#4790) 2026-06-01 18:16:49 -07:00
Victor Zverovich
46cf422f54 Unify copyright notices 2026-05-31 08:54:06 -07:00
Kağan Can Şit
9396f77fe4
Remove unused header includes in test files (#4729) 2026-04-05 18:40:48 -07:00
Victor Zverovich
882702c219 Apply clang-tidy 2025-09-01 12:21:17 -07:00
Victor Zverovich
ed0d216f7e Fix localization and formatting of timezone names 2025-04-13 09:52:59 -07:00
Victor Zverovich
bd9554a29e Fix formatting of timezone names 2025-04-13 08:52:26 -07:00
Victor Zverovich
f086dc0d27 Fix timezone handling in tm 2025-04-13 08:23:40 -07:00
Victor Zverovich
f10b6dd816 Improve chrono formatting 2025-04-12 09:59:06 -07:00
Victor Zverovich
f470b9c566 Cleanup chrono tests and set consistent TZ 2025-04-12 09:12:49 -07:00
Victor Zverovich
b28214487d Fix handling of %Z 2025-04-12 08:51:22 -07:00
Victor Zverovich
6d69f0c5f2 Improve chorno tests 2025-04-12 08:24:49 -07:00
Victor Zverovich
da776c9a66 Test timezone 2025-04-12 07:53:58 -07:00
Victor Zverovich
204661287b Improve local_time test 2025-03-29 10:56:11 -07:00
Victor Zverovich
e1ab383361 Report an error when timezone is not available 2025-03-29 09:10:00 -07:00
Victor Zverovich
b9e0e94a01 Enable more chrono tests on Windows 2025-03-29 08:20:49 -07:00
Victor Zverovich
b2dfcb2b80 Fix local_time test 2025-03-23 19:51:33 -07:00
Victor Zverovich
7ac97cbd1d Enable some local_time tests and make them deterministic 2025-03-23 11:50:03 -07:00
Victor Zverovich
17898794a9 Use fmt::local_time 2025-03-23 11:18:14 -07:00
Victor Zverovich
443a8ef342 Deprecate fmt::localtime 2025-03-23 10:46:02 -07:00
Victor Zverovich
43e31614cc Test ambiguous time 2025-03-23 10:34:37 -07:00
Khanh H
ed8f8be70d
More chrono padding (#4161)
* Add padding modifier to day of year, duration's remains unpadded
* Add padding modifier for %m, %Y
2024-09-18 09:27:45 -07:00
Victor Zverovich
79e5ae919c Fix locale tests on FreeBSD 2024-09-03 12:50:03 -07:00
Victor Zverovich
377cf203e3 Add opt out for built-in types 2024-08-29 11:21:29 -07:00
Victor Zverovich
7bd11b5cdf Remove a redundant extension to reduce divergence from std::format 2024-06-08 08:29:34 -07:00
ZaheenJ
ca8eeb09ee
Add glibc ext for day of month and week of year (#3976) 2024-05-30 10:20:56 -07:00
Victor Zverovich
c70e7b7473 Coding conventions and minor fixes 2024-04-05 08:36:45 +09:00
zivshek
71144eeaff
implement year_month_day (#3913)
* implement year_month_day, also changed weekday, day, month, year's formatter to use formatter<std::tm, Char> so they all support the format strings
* support ":L" for month and weekday
2024-04-03 15:35:53 -07:00
zivshek
74a187288b
Implemented fmt::day, fmt::month, fmt::year and related unit tests (#3906) 2024-03-27 17:10:30 -07:00
js324
34f415b56e
Fix %S formatting for chrono durations with leading zeroes (#3814) 2024-02-07 09:47:32 -08:00
Vladislav Shchapov
470c4e6ca8
Fix scope for glibc ext for sec, min, and hour (#3812)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
2024-01-16 13:54:19 -08:00
Victor Zverovich
8e6b2541a6 Apply coding conventions 2023-12-30 16:07:35 -08:00
Victor Zverovich
55190dadb5 Cleanup chrono test 2023-12-29 16:34:42 -08:00
Victor Zverovich
ea1066bbe3 Cleanup test 2023-12-28 16:56:42 -08:00