On Tue, Aug 26, 2025 at 09:11:09PM -0500, Andrew Hamilton wrote: > Support dates outside of 1901..2038. > > Fixes: https://savannah.gnu.org/bugs/?63894 > Fixes: https://savannah.gnu.org/bugs/?66301 > > Signed-off-by: Vladimir Serbinenko <phco...@gmail.com> > Signed-off-by: Andrew Hamilton <adham...@gmail.com> > --- > grub-core/lib/datetime.c | 65 ++++++++++++++++++++++++++++++++-------- > include/grub/datetime.h | 28 ++++++++++++----- > 2 files changed, 73 insertions(+), 20 deletions(-) > > diff --git a/grub-core/lib/datetime.c b/grub-core/lib/datetime.c > index 8f0922fb0..eb9a8d9c9 100644 > --- a/grub-core/lib/datetime.c > +++ b/grub-core/lib/datetime.c > @@ -64,7 +64,10 @@ grub_get_weekday_name (struct grub_datetime *datetime) > #define SECPERDAY (24*SECPERHOUR) > #define DAYSPERYEAR 365 > #define DAYSPER4YEARS (4*DAYSPERYEAR+1) > - > +/* 24 leap years in 100 years */ > +#define DAYSPER100YEARS (100 * DAYSPERYEAR + 24) > +/* 97 leap years in 400 years */ > +#define DAYSPER400YEARS (400 * DAYSPERYEAR + 97) > > void > grub_unixtime2datetime (grub_int64_t nix, struct grub_datetime *datetime) > @@ -76,10 +79,12 @@ grub_unixtime2datetime (grub_int64_t nix, struct > grub_datetime *datetime) > /* Convenience: let's have 3 consecutive non-bissextile years > at the beginning of the counting date. So count from 1901. */ > int days_epoch; > - /* Number of days since 1st Januar, 1901. */ > + /* Number of days since 1st January, 1 (proleptic). */ > unsigned days; > /* Seconds into current day. */ > unsigned secs_in_day; > + /* Tracks whether this is a leap year. */ > + bool bisextile; > > /* Transform C divisions and modulos to mathematical ones */ > if (nix < 0) > @@ -92,27 +97,63 @@ grub_unixtime2datetime (grub_int64_t nix, struct > grub_datetime *datetime) > days_epoch = grub_divmod64 (nix, SECPERDAY, NULL); > > secs_in_day = nix - days_epoch * SECPERDAY; > - days = days_epoch + 69 * DAYSPERYEAR + 17; > + /* > + * 1970 is Unix Epoch. Adjust to a year 1 epoch: > + * Leap year logic: > + * - Years evenly divisible by 400 are leap years > + * - Otherwise, if divisible by 100 are not leap years > + * - Otherwise, if divisible by 4 are leap years > + * There are four 400-year periods (1600 years worth of days with leap > days) > + * There are three 100-year periods worth of leap days (3*24)
Please move this line one line below... > + * There are 369 years in addition to the four 400 year periods > + * There are 17 leap days in 69 years (beyond the three 100 year periods) > + */ > + days = days_epoch + 369 * DAYSPERYEAR + 17 + 24 * 3 + 4 * DAYSPER400YEARS; days = 4 * DAYSPER400YEARS + 369 * DAYSPERYEAR + 3 * 24 + 17 + days_epoch; Then it is more readable... If you fix all these minor issues you can add my RB... Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel