Quote:

> I did it this way:

> 1. Convert the date to a Julian day, using the routine in the Forth

> Scientific Library, and the time to seconds since midnight (you're supposed

> to use noon with Julian days, but I'm not an astronomer).

> 2. Subtract the base offset.

> 3. Take the year of the date I'm converting and the start/end dates in

> TZInfo and figure out what the nth Sunday is that year.

> 4. Compare the two start/end dates with the result of step 2 and determine

> whether DST is in effect at that time.

> 5. Subtract either the standard offset or the daylight offset.

Just to save you some time, here's the routines I use for julian/date

conversions (based on the algorithm by Fliegel & Van Flander):

const long DateToJulian(const int y, const int m, const int d)

{

/* obs: only valid with dates 01/03/-4800 onward */

return (1461 * (y + 4800 + (m - 14) / 12)) / 4 +

(367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 -

(3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 +

d - 32075;

Quote:

}

void JulianToDate(const long jd, int *const y, int *const m,

int *const d)

{

/* obs: only valid with dates 01/03/-4900 onward */

int l = jd + 68569;

int n = (4 * l) / 146097;

int i, j;

l -= ((146097 * n + 3) / 4);

i = (4000 * (l + l)) / 1461001;

l -= ((1461 * i) / 4 + 31);

j = (80 * l) / 2447;

*d = l - (2447 * j) / 80; /* day */

l = j / 11;

*m = j + 2 - (12 * l); /* month */

*y = 100 * (n - 49) + i + l; /* year */

Quote:

}

These assume >= 32-bit int. If your system has >= 32-bit longs but not

ints, change ints to longs and put an extra L after numeric values to

make them long constants.

Since the original Julian dates do not have times, neither do these

routines. The time system was added by astronomers to have an easy way

for counting times. They use 12pm (or noon) to be the start of the day,

because the night thus falls nicely into one day, and represent times as

fractions of the day (noon = .0, 6am = .25, midday = .50 and 6pm = .75,

for example).

HTH,

AriL

--

*DO NOT* send me email unless I ask you to.

I read the answers where I ask the questions.

This may also help some other people.