[Chugalug] Calculating the next Thanksgivukkah

Robert A. Kelly III bluethegrappler at gmail.com
Wed Oct 9 03:37:29 UTC 2013


On 10/08/2013 09:39 PM, Robert A. Kelly III wrote:
> I found the problem in the HebToJul() function in hbcal.c:
> 
> int HebToJul(int hy, int hm, int hd)
> {
>     int ylen;
>     char const *monlens;
>     int rh;
>     int m;
> 
>     /* Do some range checking */
>     if (hy - 3761 < BASE || hy - 3760 > BASE+YR_RANGE) return -1;
> 
>     ylen = DaysInHebYear(hy);
>     monlens = DaysInHebMonths(ylen);
> 
>     /* Get the Rosh Hashana of the year */
>     rh = RoshHashana(hy);
> 
>     /* Bump up to the appropriate month */
>     for (m=0; m<hm; m++) rh += monlens[m];
> 
>     /* Add in appropriate number of days */
>     rh += hd - 1;
>     return rh;
> }
> 
> When this function returns <0, GetNextHebrewDate() returns E_DATE_OVER.
> Quick and dirty fix, commenting out the range checking line allowed me
> to determine that the next date of Thanksgivukkah is indeed November 23,
> 79043!

A further examination shows that YR_RANGE is based on the assumption of
a 32-bit signed integer:

/*---------------------------------------------------------------------*/
/* YR_RANGE: The range of years allowed.  With 32-bit signed integers, */
/* the DATETIME type can store 2^31 minutes or about 4074 years.       */
/*---------------------------------------------------------------------*/
#define YR_RANGE 4000

With a 64-bit signed integer, it should be safe to use:

#define YR_RANGE 17536635926176

Incidentally, I also noticed that the location for calculating things
like sunrise and sunset is hardcoded with the assumption of Ottawa,
Ontario, Canada. I guess remind really was intended to be compiled by
the user, LOL. It truly is, there is actually a GUI that lets you set
your latitude and longitude when you compile it. YR_RANGE, however, is
not intended to be altered so easily. The compile script should probably
automatically check for a 64-bit architecture and adjust accordingly.


More information about the Chugalug mailing list