home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / amiga / programm / 12608 < prev    next >
Encoding:
Text File  |  1992-08-23  |  3.0 KB  |  90 lines

  1. Path: sparky!uunet!decwrl!csus.edu!netcom.com!netcomsv!terapin!paulk
  2. From: paulk@terapin.com (Paul Kienitz)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Fun w/DateStamp
  5. References: <1992Aug22.190411.1049@CS.ORST.EDU>
  6. Message-ID: <paulk.18lk@terapin.com>
  7. Date: 23 Aug 92 16:34:03 PST
  8. Organization: BBS
  9. Lines: 79
  10.  
  11. > I need to deduce the current date.  DateStamp does the trick, of
  12. > course, but how useful is the number of days since Jan. 1, 1978???
  13. > Does anyone know of a function or #define in the .h files somewhere
  14. > that translates this cryptic "internal format" into something
  15. > humans use?
  16.  
  17.  
  18. Here is a sample function from a program of mine ...  if the RawDoFmt
  19. calls are confusing, just pretend that they are funny-looking
  20. sprintf()s.
  21.  
  22. void formdate(char *s, struct DateStamp *when)
  23. {
  24.     long day = when->ds_Days;
  25.     register short yell, mday, month, year;
  26.     short hour = (short) when->ds_Minute / 60,
  27.                 minute = (short) when->ds_Minute % 60,
  28.                 second = (short) when->ds_Tick / (short) TICKS_PER_SECOND;
  29.     static char mane[] = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0"
  30.                                 "Sep\0Oct\0Nov\0Dec";
  31.     static short smods[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  32.     short mods[12];
  33.     struct { short d; char *m; short y; } arzg1;
  34.     short arzg2[3];
  35.     char *f;
  36.     void mob(char c, char *b);
  37.  
  38. #ifdef WEEEEK
  39.     /* betcha the reason they started the calendar from the beginning of
  40.        1978 in particular is because that way day zero is a Sunday */
  41.     static char *weak[7] = { "Sunday   ", "Monday   ", "Tuesday  ",
  42. "Wednesday",
  43.                                 "Thursday ", "Friday   ", "Saturday " };
  44.     struct DateStamp today;
  45.     short daydif;
  46.  
  47.     DateStamp(&today);
  48.     daydif = today.ds_Days - day;
  49.     if (!daydif)
  50.         strcpy(s, "Today    ");
  51.     else if (daydif == 1)
  52.         strcpy(s, "Yesterday");
  53.     else if (daydif > 1 && daydif < 7)
  54.         strcpy(s, weak[day % 7]);
  55.     else
  56. #endif
  57.     {
  58.         if (day <= 0 || day >= 44618)
  59.             strcpy(s, "<invalid>");
  60.         else {
  61.             year = 78 + ((day / 1461) << 2);
  62.             mday = day % 1461;
  63.             while (mday >= (yell = (year & 3 ? 365 : 366))) {
  64.                 mday -= yell;
  65.                 year++;
  66.             }
  67.             /* 2000 is a leap year, 1900 and 2100 are <invalid> */
  68.             for (month = 0; month < 12; month++)
  69.                 mods[month] = smods[month];
  70.             if (!(year & 3)) mods[1] = 29;
  71.             month = 0;
  72.             while (mday >= mods[month])
  73.                 mday -= mods[month++];
  74.             arzg1.d = mday + 1;
  75.             arzg1.m = mane + (month << 2);
  76.             arzg1.y = year % 100;
  77.             RawDoFmt("%2d-%s-%02d", (adr) &arzg1, mob, s);
  78.         }
  79.     }
  80.     if (hour < 0 || hour >= 24)
  81.         strcpy(s + 9, " <invalid>");
  82.     else {
  83.         arzg2[0] = hour;
  84.         arzg2[1] = minute;
  85.         arzg2[2] = second;
  86.         f = (second < 0 || second >= 60 ? " %2d:%02d:??" : " %2d:%02d:%02d");
  87.         RawDoFmt(f, (adr) arzg2, mob, s + 9);
  88.     }
  89. }
  90.