source: buchla-68k/orig/DATE/DATETX.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: 2.9 KB
RevLine 
[3ae31e9]1/*
2 * Convert Date to Readable Format.
3 *
4 * Synopsis:
5 *
6 * char *datetxt(buffer, year, month, day);
7 * char *buffer; -- Output string goes here
8 * int year; -- Year, 1979 = 1979
9 * int month; -- Month, January = 1
10 * int day; -- Day, 1 = 1
11 *
12 * The readable date will be written into the outpub buffer, terminated by
13 * a null byte. datetxt returns a pointer to the null byte.
14 *
15 * External routines called:
16 *
17 * nbrtxt (Number to ascii conversion)
18 * copyst (String copy routine)
19 */
20
21extern char *nbrtxt();
22extern char *copyst();
23extern char *datetxt();
24
25static char *daynames[] = {
26 "Sunday", /* Sunday is day zero */
27 "Monday",
28 "Tuesday",
29 "Wednesday",
30 "Thursday",
31 "Friday",
32 "Saturday",
33};
34
35static char *monthnames[] = {
36 "?Nomember?", /* Illegal month */
37 "January",
38 "February",
39 "March",
40 "April",
41 "May",
42 "June",
43 "July",
44 "August",
45 "September",
46 "October",
47 "November",
48 "December",
49};
50
51char *datetxt(buffer, year, month, day)
52char *buffer; /* Output goes here */
53int year; /* Year, 1979 = 1979 */
54int month; /* Month of year, Jan = 1 */
55int day; /* Day in the month 1 = 1 */
56/*
57 * Output the date in readable format:
58 * Tuesday, the third of October
59 */
60{
61 register char *op; /* Output pointer */
62
63 op = buffer; /* Setup output pointer */
64 op = copyst(op, daynames[dayofweek(year, month, day)]);
65 op = copyst(op, ", the ");
66 op = nbrtxt(op, day, 1);
67 op = copyst(op, " day of ");
68 op = copyst(op, monthnames[(month < 0 || month > 12) ? 0 : month]);
69 op = copyst(op, ", ");
70 if (year < 1000 || year >= 2000)
71 return(nbrtxt(op, year, 0));
72 else {
73 op = nbrtxt(op, year/100, 0);
74 op = copyst(op, " ");
75 if ((year = year % 100) == 0)
76 return(copyst(op, "hundred"));
77 else
78 return(nbrtxt(op, year, 0));
79 }
80}
81
82dayofweek(year, month, day)
83int year; /* Year, 1978 = 1978 */
84int month; /* Month, January = 1 */
85int day; /* Day of month, 1 = 1 */
86/*
87 * Return the day of the week on which this date falls: Sunday = 0.
88 * Note, this routine is valid only for the Gregorian calender.
89 */
90{
91 register int yearfactor;
92
93 yearfactor = year + (month - 14)/12;
94 return (( (13 * (month + 10 - (month + 10)/13*12) - 1)/5
95 + day + 77 + 5 * (yearfactor % 100)/4
96 + yearfactor / 400
97 - yearfactor / 100 * 2) % 7);
98}
99
Note: See TracBrowser for help on using the repository browser.