From 31ff86ee6b346a90d51c9e0c5b43693967b4457b Mon Sep 17 00:00:00 2001 From: Lily Wilson Date: Fri, 10 Oct 2025 07:03:23 -0400 Subject: [PATCH 1/2] fix leap year calculation and remove now-unnecessary timestamp limit Signed-off-by: Lily Wilson --- date.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/date.c b/date.c index 17a95077cf5450..314dec277e1964 100644 --- a/date.c +++ b/date.c @@ -24,7 +24,7 @@ time_t tm_to_time_t(const struct tm *tm) int month = tm->tm_mon; int day = tm->tm_mday; - if (year < 0 || year > 129) /* algo only works for 1970-2099 */ + if (year < 0) /* algo only works for 1970+ */ return -1; if (month < 0 || month > 11) /* array bounds */ return -1; @@ -33,6 +33,7 @@ time_t tm_to_time_t(const struct tm *tm) if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0) return -1; return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + + (year + 369) / 400 - (year + 69) / 100 + tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; } @@ -526,7 +527,7 @@ static int set_date(int year, int month, int day, struct tm *now_tm, time_t now, return 1; r->tm_year = now_tm->tm_year; } - else if (year >= 1970 && year < 2100) + else if (year >= 1970) r->tm_year = year - 1900; else if (year > 70 && year < 100) r->tm_year = year; @@ -871,8 +872,8 @@ static int match_object_header_date(const char *date, timestamp_t *timestamp, in } -/* timestamp of 2099-12-31T23:59:59Z, including 32 leap days */ -static const timestamp_t timestamp_max = (((timestamp_t)2100 - 1970) * 365 + 32) * 24 * 60 * 60 - 1; +/* timestamp of max time */ +static const timestamp_t timestamp_max = UINTMAX_MAX; /* Gr. strptime is crap for this; it doesn't have a way to require RFC2822 (i.e. English) day/month names, and it doesn't work correctly with %z. */ From ff6d4f74f027f88414d87c8ff38f83cd1bb6bf19 Mon Sep 17 00:00:00 2001 From: Lily Wilson Date: Fri, 10 Oct 2025 07:14:47 -0400 Subject: [PATCH 2/2] fix whitespace Signed-off-by: Lily Wilson --- date.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/date.c b/date.c index 314dec277e1964..57105938796d00 100644 --- a/date.c +++ b/date.c @@ -33,7 +33,7 @@ time_t tm_to_time_t(const struct tm *tm) if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_sec < 0) return -1; return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + - (year + 369) / 400 - (year + 69) / 100 + + (year + 369) / 400 - (year + 69) / 100 + tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; }