Bug 267266 - maximum date off by 1900 years from 32-bit tm_year max value?
Summary: maximum date off by 1900 years from 32-bit tm_year max value?
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-22 03:08 UTC by jschauma
Modified: 2024-01-20 22:41 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jschauma 2022-10-22 03:08:11 UTC
With tm_year being a signed 32-bit int, the maximum date I should be able to represent ought to be

Wed Dec 31 23:59:59 UTC 2147485547

which is epoch 67768036191676799.

This works on Linux and NetBSD, for example, as well as macOS.

On FreeBSD 13.1R, however, it does not:

$ date -r 67768036191676799
date: invalid time
$ date -r 67767976233532799
Tue Dec 31 23:59:59 UTC 2147483647
$ date -r 67767976233532800
date: invalid time

Note that here the maximum value (epoch 67767976233532799) is in the year 2147483647, not in the year 2147485547.  The difference between the two is 1900, suggesting that FreeBSD somehow counts tm_year as starting at the year 0, not 1900.  However, I can't identify where/when that is the case, as other dates correctly display tm_year as "year - 1900":


        struct tm *t;
        time_t now = time(NULL);

        t = gmtime(&now);
        printf("%s%ld %d\n", ctime(&now), now, t->tm_year);

=>

Sat Oct 22 03:06:43 2022
1666408003 122

It's unclear to me why FreeBSD then can't represent 67768036191676799.
Comment 1 Philip Paeps freebsd_committer freebsd_triage 2022-11-02 02:41:44 UTC
I believe this has been fixed upstream in more recent tzcode releases.  The tzcode in FreeBSD has languished since approximately 2010.  I have about 80% of an import to a more recent version done ... the easy 80% ... the more difficult 80% is taking forever.
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2024-01-20 22:41:54 UTC
^Triage: most likely fixed by or before rG75411d157232: Update tzcode to 2023c Apr 26 2023.