home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!decwrl!csus.edu!netcom.com!netcomsv!terapin!paulk
- From: paulk@terapin.com (Paul Kienitz)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Fun w/DateStamp
- References: <1992Aug22.190411.1049@CS.ORST.EDU>
- Message-ID: <paulk.18lk@terapin.com>
- Date: 23 Aug 92 16:34:03 PST
- Organization: BBS
- Lines: 79
-
- > I need to deduce the current date. DateStamp does the trick, of
- > course, but how useful is the number of days since Jan. 1, 1978???
- > Does anyone know of a function or #define in the .h files somewhere
- > that translates this cryptic "internal format" into something
- > humans use?
-
-
- Here is a sample function from a program of mine ... if the RawDoFmt
- calls are confusing, just pretend that they are funny-looking
- sprintf()s.
-
- void formdate(char *s, struct DateStamp *when)
- {
- long day = when->ds_Days;
- register short yell, mday, month, year;
- short hour = (short) when->ds_Minute / 60,
- minute = (short) when->ds_Minute % 60,
- second = (short) when->ds_Tick / (short) TICKS_PER_SECOND;
- static char mane[] = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0"
- "Sep\0Oct\0Nov\0Dec";
- static short smods[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- short mods[12];
- struct { short d; char *m; short y; } arzg1;
- short arzg2[3];
- char *f;
- void mob(char c, char *b);
-
- #ifdef WEEEEK
- /* betcha the reason they started the calendar from the beginning of
- 1978 in particular is because that way day zero is a Sunday */
- static char *weak[7] = { "Sunday ", "Monday ", "Tuesday ",
- "Wednesday",
- "Thursday ", "Friday ", "Saturday " };
- struct DateStamp today;
- short daydif;
-
- DateStamp(&today);
- daydif = today.ds_Days - day;
- if (!daydif)
- strcpy(s, "Today ");
- else if (daydif == 1)
- strcpy(s, "Yesterday");
- else if (daydif > 1 && daydif < 7)
- strcpy(s, weak[day % 7]);
- else
- #endif
- {
- if (day <= 0 || day >= 44618)
- strcpy(s, "<invalid>");
- else {
- year = 78 + ((day / 1461) << 2);
- mday = day % 1461;
- while (mday >= (yell = (year & 3 ? 365 : 366))) {
- mday -= yell;
- year++;
- }
- /* 2000 is a leap year, 1900 and 2100 are <invalid> */
- for (month = 0; month < 12; month++)
- mods[month] = smods[month];
- if (!(year & 3)) mods[1] = 29;
- month = 0;
- while (mday >= mods[month])
- mday -= mods[month++];
- arzg1.d = mday + 1;
- arzg1.m = mane + (month << 2);
- arzg1.y = year % 100;
- RawDoFmt("%2d-%s-%02d", (adr) &arzg1, mob, s);
- }
- }
- if (hour < 0 || hour >= 24)
- strcpy(s + 9, " <invalid>");
- else {
- arzg2[0] = hour;
- arzg2[1] = minute;
- arzg2[2] = second;
- f = (second < 0 || second >= 60 ? " %2d:%02d:??" : " %2d:%02d:%02d");
- RawDoFmt(f, (adr) arzg2, mob, s + 9);
- }
- }
-