source: buchla-68k/orig/DATE/GREG.txt@ 6888aa2

Last change on this file since 6888aa2 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 11.0 KB
Line 
1
2
3
4 GGGGRRRREEEEGGGG((((1111)))) UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll)))) GGGGRRRREEEEGGGG((((1111))))
5
6
7
8 NNNNAAAAMMMMEEEE
9 greg - compute details of Gregorian calendar
10
11 SSSSYYYYNNNNTTTTAAAAXXXX
12 ggggrrrreeeegggg YYYYeeeeaaaarrrr MMMMoooonnnntttthhhh DDDDaaaayyyyOOOOffffMMMMoooonnnntttthhhh [[[[DDDDaaaayyyyOOOOffffWWWWeeeeeeeekkkk WWWWeeeeeeeekkkkOOOOffffMMMMoooonnnntttthhhh DDDDaaaayyyyOOOOffffYYYYeeeeaaaarrrr
13 JJJJuuuulllliiiiaaaannnnDDDDaaaayyyy]]]]
14
15 SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
16 _G_r_e_g provides calendar information. It approximates the
17 functionality of unix cal except that the information is
18 provided in a way that is appropriate for use in other
19 programs rather than visual display.
20
21 The internal function "gregorian" is designed to be used as
22 a component of other programs.
23
24 DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
25 The program is invertible in the sense of a logic
26 programming predicate. That is, inputs with positive values
27 are checked for consistency; missing inputs (indicated by
28 otherwise illegal value 0) are given the correct positive
29 value if possible.
30
31 If all the output is correct, the program will exit with 0.
32
33 If the input cannot be reconciled, the program will exit
34 with 1.
35
36 If the input leaves the output indeterminate, the program
37 will exit with 2.
38
39 If the C implementation cannot support the calculation
40 because of arithmetic precision, the program will exit with
41 3.
42
43 PPPPAAAARRRRAAAAMMMMEEEETTTTEEEERRRRSSSS
44 There are seven related inputs. Inputs 1-3 are required.
45 If inputs 4-7 are omitted, zero is assumed for each.
46
47 The _Y_e_a_r is an integer >= _1_5_8_2
48
49 The _M_o_n_t_h is an integer between _1 and _1_2.
50
51 The _D_a_y_O_f_M_o_n_t_h is an integer between _1 and _2_8, _2_9, _3_0 or _3_1
52 depending on the month.
53
54 The _D_a_y_O_f_W_e_e_k is an integer between _1 and _7 corresponding to
55 _S_u_n_d_a_y, _M_o_n_d_a_y, ... _S_a_t_u_r_d_a_y. It is the column position of
56 the date in the conventional monthly calendar tableau.
57
58 The _W_e_e_k_O_f_M_o_n_t_h is an integer between _1 and _6 corresponding
59 to weeks in the calendar month. It is the row position of
60
61
62
63 Page 1 (printed 3/10/86)
64
65
66
67
68
69
70 GGGGRRRREEEEGGGG((((1111)))) UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll)))) GGGGRRRREEEEGGGG((((1111))))
71
72
73
74 the date in the conventional monthly calendar tableau. The
75 first of the month is always in week _1.
76
77 The _D_a_y_O_f_Y_e_a_r is an integer between _1 and _3_6_5 or _3_6_6
78
79 The _J_u_l_i_a_n_D_a_y is an integer >= _2_2_9_9_1_6_1, corresponding to _1_5
80 _O_c_t_o_b_e_r, _1_5_8_2. It measures the time in days from 1 Jan 4713
81 BC (Julian calendar). Each julian day starts at noon, GMT
82 of the corresponding day of the Gregorian calendar.
83 Astronomers express the relation between julian day j and
84 date d as dd.5/mm/yyyy = j.0 where both "day"s are real
85 numbers. dd.5 is noon of day dd. j.0 is the beginning of
86 julian day j.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 Page 2 (printed 3/10/86)
130
131
132
133
134
135
136 GGGGRRRREEEEGGGG((((1111)))) UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll)))) GGGGRRRREEEEGGGG((((1111))))
137
138
139
140 There are four patterns of input for the seven parameters
141 that can possibly give a correct result. They are given
142 below. P signifies positive integer (an input). ?
143 signifies either 0 (an unknown) or a positive integer (an
144 input).
145 P P P ? -- year
146 P ? P ? -- month of year
147 P ? ? ? -- day of month
148 ? ? P ? -- day of week
149 ? ? P ? -- week of month
150 ? P ? ? -- day of year
151 ? ? ? P -- julian day
152
153 FFFFIIIILLLLEEEESSSS
154 none
155
156 MMMMEEEETTTTHHHHOOOODDDD
157 The Gregorian Calendar was adopted starting October 15, 1582
158 (September 14, 1752 in Britain and her colonies). Dates
159 prior to adoption were in the Julian Calendar system (no
160 relation to julian days). Dates before the conversion are
161 denoted OS (old system); dates after the conversion are
162 denoted NS (new system). This program will extrapolate
163 Gregorian dates back to 1 AD although it will issue a
164 warning (inconsistent) for dates prior to the adoption of
165 the Gregorian calendar. 1 BC OS immediately preceded 1 AD
166 OS (no year 0) so the algorithms are invalid, even for
167 extrapolation, prior to 1 AD.
168
169 The algorithms, some from the references below, are
170 tableless. The collection given here is valid from January
171 1, 1 AD NS. The algorithms, which depend on a number of _a_d
172 _h_o_c functions over integers, are cryptic but the alternative
173 of using tables does not help much. The notation is C.
174 Logical values are to be interpreted as 1 == true and 0 ==
175 false. Where it is supposed that the names of the functions
176 are not sufficiently mnemonic, an italic comment is
177 appended. The code in gregorian.c is algebraically
178 simplified where possible when the functions below are back
179 substituted into other defining formulas. More than one
180 version is given for some formulas.
181
182 LeapsBefore(y) == (y-1)/4 - (y-1)/100 + (y-1)/400 _l_e_a_p _y_e_a_r_s _b_e_t_w_e_e_n _1 _A_D _a_n_d _y_e_a_r _y
183
184 Leap(y) == LeapsBefore(y+1) - LeapsBefore(y)
185
186 Leap(y) == y%400 == 0 || (y%100 != 0 && y%4 == 0)
187
188 StonesNumber(y, yd) == (yd + (yd>59+Leap(y))*(2-Leap(y)) + 91)*100
189
190 DaysInYearBefore(m, y) == 3055*(m+2)/100 - 91 - (m>2)*(2-Leap(y))
191
192
193
194
195 Page 3 (printed 3/10/86)
196
197
198
199
200
201
202 GGGGRRRREEEEGGGG((((1111)))) UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll)))) GGGGRRRREEEEGGGG((((1111))))
203
204
205
206 DayOfYear(y, m, d) == DaysInYearBefore(m, y) + d
207
208 MonthOfYear(y, yd) == StonesNumber(y, yd)/3055 - 2
209
210 DayOfMonth(y, yd) == StonesNumber(y, yd)%3055/100 + 1
211
212 DaysInYear(y) == 365 + Leap(y)
213
214 DaysInYear(y) == DaysInYearBefore(13, y)
215
216 DaysInMonth(m, y) == ((m == 2) ? 28+Leap(y) : 30+(m==1 || m%5%3 != 1))
217
218 DaysInMonth(m, y) == DaysInYearBefore(m+1, y) - DaysInYearBefore(m, y)
219
220 JulianDaysB4(y) == (y-1)*365 + LeapsBefore(y) + 1721425
221
222 JulianDay(y, m, d) == JulianDaysBefore(y) + DayOfYear(y, m, d)
223
224 YearOf(jd) = 1 + (jd-=(17214256), jd-=(jd+1)/146097, jd+=(jd+1)/36524, jd-(jd+1)/1461)/365
225 _y_e_a_r _i_n _w_h_i_c_h _j_u_l_i_a_n _d_a_y _j_d _o_c_c_u_r_s
226 DayOf(jd) == jd - JulianDaysBefore(YearOf(jd))
227 _g_i_v_e_n _t_h_e _j_u_l_i_a_n _d_a_y _j_d, _d_a_y _o_f _y_e_a_r _f_r_o_m _1 _J_a_n
228
229 WeekDay(jd) = (jd+1)%7+1 _S_u_n_d_a_y = _1, _e_t_c.
230
231 Week(dm, dw) = (13 + dm - dw)/7
232 _w_e_e_k _o_f _m_o_n_t_h _f_r_o_m _d_a_y _o_f _m_o_n_t_h _a_n_d _d_a_y _o_f _w_e_e_k
233
234 LLLLIIIIMMMMIIIITTTTSSSS
235 Inputs are converted by _a_t_o_i which does not check for non-
236 digits. The julian day is, by definition, bounded from
237 below by 2299161 (15 October, 1582). The program will fail
238 for implementations of C with _s_i_z_e_o_f (_l_o_n_g _i_n_t) < _4. There
239 is no practical upper limit on year or julian day. The
240 program extrapolates backward correctly to January 1, 1 AD
241 NS but reports the input is "inconsistent" prior to October
242 15, 1582.
243
244 SSSSEEEEEEEE AAAALLLLSSSSOOOO
245 1. Any almanac, under calendar, perpetual. (Note the World
246 Almanac (1985, 1986) gives a julian day incorrect by one).
247
248 2. Any encyclopedia, under calendar.
249
250 3. The Astronomical Ephemeris (any year)
251
252 3. CAL(1). The information supplied by greg corresponds to
253 cal starting September 14, 1752 AD.
254
255 4. Elmore, Perpetual Calendar, Am.J.Phys.44,3 (May 1976) pp
256 482-3.
257
258
259
260
261 Page 4 (printed 3/10/86)
262
263
264
265
266
267
268 GGGGRRRREEEEGGGG((((1111)))) UUUUNNNNIIIIXXXX 5555....0000 ((((llllooooccccaaaallll)))) GGGGRRRREEEEGGGG((((1111))))
269
270
271
272 5. Fliegel & Van Flandern, A Machine Algorithm for
273 Processing Calendar Dates, (letter to the editor) CACM 11,10
274 (October 1968) pg. 657.
275
276 6. Stone, Tableless Date Conversion. Algorithm 398.
277 Collected Algorithms from the CACM (rcvd Jan 1970) and a
278 Remark by Robertson (rcvd Dec 1970).
279
280 7. Tantzen, Conversions Between Calendar Date and Julian Day
281 Number, Algorithm 199. Collected Algorithms from the CACM
282 (August 1963).
283
284 8. Uspensky & Heaslet, Elementary Number Theory, McGraw-
285 Hill, (1939) p.206-221.
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 Page 5 (printed 3/10/86)
328
329
330
331
Note: See TracBrowser for help on using the repository browser.