mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 19:24:48 +02:00
Fix overflow for very bigger years (>2*10^9) (#2551)
This commit is contained in:
committed by
GitHub
parent
1266c2b600
commit
7463c83205
@@ -1420,14 +1420,15 @@ template <typename OutputIt, typename Char> class tm_writer {
|
|||||||
|
|
||||||
// Algorithm:
|
// Algorithm:
|
||||||
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_from_a_month_and_day_of_the_month_or_ordinal_date
|
// https://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_from_a_month_and_day_of_the_month_or_ordinal_date
|
||||||
auto iso_year_weeks(const int curr_year) const noexcept -> int {
|
auto iso_year_weeks(const int year) const noexcept -> int {
|
||||||
const int prev_year = curr_year - 1;
|
const long long curr_year = year;
|
||||||
const int curr_p =
|
const long long prev_year = curr_year - 1;
|
||||||
|
const int curr_p = static_cast<int>(
|
||||||
(curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
|
(curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) %
|
||||||
days_per_week;
|
days_per_week);
|
||||||
const int prev_p =
|
const int prev_p = static_cast<int>(
|
||||||
(prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
|
(prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) %
|
||||||
days_per_week;
|
days_per_week);
|
||||||
return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
|
return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0);
|
||||||
}
|
}
|
||||||
auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int {
|
auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int {
|
||||||
|
Reference in New Issue
Block a user