[part 4 of 5] 3.5 GREGORIAN DATE FROM DD To determine the Gregorian date of any day from its positive DD day-number carry out the following steps. a) Let `x' = DD - 1 [days in era before this] b) Let `gyr' = ((`x' DIV 146097) * 400) [yrs in whole 400-yr cycles] c) Let `x' = `x' MOD 146097 [remaining number of days] d) Let `z' = `x' DIV 36524 [no. of remaining centuries] e) If (`z' = 4) then let `z' = 3 [last day of a leap year] f) Let `gyr' = `gyr' + (`z' * 100) [years in whole centuries] g) Let `x' = `x' MOD 36524 [remaining number of days] h) Let `gyr' = `gyr' + ((`x' DIV 1461) * 4) [years in whole 4-yr cycles] i) Let `x' = `x' MOD 1461 [remaining number of days] j) Let `z' = `x' DIV 365 [number of remaining years] k) If (`z' = 4) then let `z' = 3 [last day of a leap year] l) Let `gyr' = `gyr' + `z' + 1 [odd years + 1 for this year] m) `gyr' is the required Gregorian AD year-number n) Let `x' = (`x' MOD 365) + 1 [day-number within `gyr'] o) Determine whether the year `gyr' was (is, will be) a leap year, and whether 29th February in that year is included in DD, as follows. if (`x' > 59) AND ((`gyr' MOD 400) = 0) OR (((`gyr' MOD 100) <> 0) AND ((`gyr' MOD 4) = 0)) then let `gly' = 1 else let `gly' = 0 p) Search the following table backwards from the end to find the first (ie. latest in the year) month for which (`x' - `gly') > `gdp' `gmn' Month `gdp' 1 Jan 0 2 Feb 31 3 Mar 59 (`gly' will deal with leap years) 4 Apr 90 5 May 120 6 Jun 151 7 Jul 181 8 Aug 212 9 Sep 243 10 Oct 273 11 Nov 304 12 Dec 334 p) `gmn' is the required month q) Let `gdm' = `d' - `gdp' - `gly' r) If `d' = 60 [ie. the day is the 60th of the year - 1st March or 29th February] then let `gdm' = `gdm' + `gly' s) The required date is `gdm' of `gmn', AD `gyr' 3.6 JULIAN DATE FROM DD To determine the Julian date of any day from its positive DD day-number carry out the following steps. a) Let `x' = DD - 1 [days in era before this] b) allow for Augustus' adjustments as follows if DD < 4382 [on or before 1st Jan. AD 12] then let `jyr' = 0 and continue at (e) following [skip leap year cycle] else let `x' = `x' + 2 [29th Feb. in AD 4 and AD 8] continue at (c) following c) Let `jyr' = ((`x' DIV 1461) * 4) [years in whole 4-yr cycles] d) Let `x' = `x' MOD 1461 [remaining number of days] e) Let `z' = `x' DIV 365 [number of remaining years] f) If (`x' = 12) then let `x' = 11 [last day of a leap year] g) If (steps (c) and (e) have been done) AND (`z' = 4) then let `z' = 3 [last day of a leap year] h) Let `jyr' = `jyr' + `z' + 1 [odd years + 1 for this year] i) `jyr' is the required Julian AD year-number j) Let `x' = (`x' MOD 365) + 1 [day-number within `jyr'] k) Determine whether the year `jyr' was (is, will be) a leap year, and whether 29th February in that year is included in DD, as follows. if (`x' > 59) AND (`jyr' > 8) AND ((`jyr' MOD 4) = 0) then let `gly' = 1 else let `gly' = 0 l) Search the following table backwards from the end to find the first (ie. latest in the year) month for which (`x' - `jly') > `jdp' `jmn' Month `jdp' 1 Jan 0 2 Feb 31 3 Mar 59 (`jly' will deal with leap years) 4 Apr 90 5 May 120 6 Jun 151 7 Jul 181 8 Aug 212 9 Sep 243 10 Oct 273 11 Nov 304 12 Dec 334 m) `jmn' is the required month q) Let `jdm' = `d' - `jdp' - `jly' n) If `d' = 60 [ie. the day is the 60th of the year - 1st March or 29th February] then let `jdm' = `jdm' + `jly' o) The required date is `jdm' of `jmn', AD `jyr' 3.7 DAY OF WEEK FROM DD To determine the day of the week for any day from its DD day-number carry out the following steps. a) Let `dow' = (DD MOD 7) b) Extract the day of the week from the following table. `dow' Day `dow' Day 0 Sunday 4 Thursday 1 Monday 5 Friday 2 Tuesday 6 Saturday 3 Wednesday 3.8 CONVERSION BETWEEN GREGORIAN AND JULIAN DATES Convert to DD as an intermediate step, then to the required date. [continued in part 5] --- WtrGate v0.93.p9 Unreg * Origin: Khanya BBS, Tshwane, South Africa [012] 333-0004 (5:7106/20) SEEN-BY: 633/267 270 @PATH: 7106/20 22 140/1 106/2000 633/267