source: buchla-68k/orig/DATE/JDATE.C@ 73dd55f

Last change on this file since 73dd55f was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.4 KB
RevLine 
[3ae31e9]1/*
2 =============================================================================
3 jdate.c -- Julian date converter -- ACM Algorithm 199
4
5 Algorithm 199 from Collected algorithms of the ACM.
6
7 Takes a julian date (the number of days since some distant epoch
8 or other), and a pointer to a result array. Returns a pointer to the
9 filled in result array:
10
11 ip[0] = month;
12
13 ip[1] = day of month;
14
15 ip[2] = year (actual year, like 1977,
16 not 77 unless it was 77 a.d.);
17
18 ip[3] = day of week (0->Sunday to 6->Saturday)
19
20 The Gregorian calendar is assumed.
21
22 Written by: Robert G. Tantzen
23
24 Translated to C by: Nat Howard
25
26 Revisions by:
27
28 D.N. Lynx Crowe 1988-01-14
29 optimized for speed and adapted for re-entrancy
30 =============================================================================
31*/
32
33/*
34
35*/
36
37int *
38jdate(j, ret)
39register long j;
40register int *ret;
41{
42 register long d, m, y, k;
43
44 ret[3] = (j + 1L) % 7L;
45
46 j -= 1721119L;
47
48 k = (4L * j) - 1L;
49 y = k / 146097L;
50 j = k - (146097L * y);
51 d = j / 4L;
52
53 k = (4L * d) + 3L;
54 j = k / 1461L;
55 d = k - (1461L * j);
56 d = (d + 4L) / 4L;
57
58 k = (5L * d) - 3L;
59 m = k / 153L;
60 d = k - (153L * m);
61 d = (d + 5L) / 5L;
62 y = (100L * y) + j;
63
64 if(m < 10) {
65
66 m += 3;
67
68 } else {
69
70 m -= 9;
71 ++y;
72 }
73
74 ret[0] = m;
75 ret[1] = d;
76 ret[2] = y;
77
78 return(ret);
79}
Note: See TracBrowser for help on using the repository browser.