source: buchla-68k/orig/DATE/TODAY.C@ 6099cac

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

Imported original source code.

  • Property mode set to 100755
File size: 1.9 KB
Line 
1/*
2 =============================================================================
3 today.c -- print the date and time of day
4 Version 1 -- 1988-12-05 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "osbind.h"
9#include "stddefs.h"
10
11char *days[] = {
12
13 "Sunday",
14 "Monday",
15 "Tuesday",
16 "Wednesday",
17 "Thursday",
18 "Friday",
19 "Saturday"
20};
21
22char *mons[] = {
23
24 "January",
25 "February",
26 "March",
27 "April",
28 "May",
29 "June",
30 "July",
31 "August",
32 "September",
33 "October",
34 "November",
35 "December"
36};
37
38/*
39
40*/
41
42/*
43 =============================================================================
44 wkday() -- determine the day of the week by Zeller's Congruence
45
46 Uses the Gregorian calendar -- accurate from 1752 through 4901 A.D.
47
48 short
49 wkday(year, month, day)
50 short year, month, day;
51
52 year 1752..4901
53 month 1..12 1 = Jan., 2 = Feb., ..., 12 = Dec.
54 day 1..31
55
56 Returns:
57
58 0 - Sunday
59 1 - Monday
60 2 - Tuesday
61 3 - Wednesday
62 4 - Thursday
63 5 - Friday
64 6 - Saturday
65 =============================================================================
66*/
67
68short
69wkday(year, month, day)
70register short year, month, day;
71{
72 register short cen, yinc;
73
74 month -= 2;
75
76 if (month < 1) {
77
78 month += 12;
79 --year;
80 }
81
82 cen = year / 100;
83 yinc = year - (cen * 100);
84
85 return(((((26 * month) - 2) / 10) + day + yinc + (yinc / 4)
86 + (cen / 4) - (2 * cen)) % 7);
87}
88
89/*
90
91*/
92
93main()
94{
95 register long t;
96 short yr, mn, dy, hh, mm, ss;
97
98 t = Gettime();
99
100 yr = ((short)(t >> 25) & 0x007F) + 1980;
101 mn = (short)(t >> 21) & 0x000F;
102 dy = (short)(t >> 16) & 0x001F;
103
104 hh = (short)(t >> 11) & 0x001F;
105 mm = (short)(t >> 5) & 0x003F;
106 ss = ((short)t & 0x001F) << 1;
107
108 printf("It is %02d:%02d:%02d on %s, %s %d, %d.\n",
109 hh, mm, ss,
110 days[wkday(yr, mn, dy)],
111 mons[mn - 1], dy, yr);
112
113 exit(0);
114}
Note: See TracBrowser for help on using the repository browser.