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

  1. Path: sparky!uunet!ivgate!oaminet!Michael.Groshart
  2. From: Michael.Groshart@oaminet.omahug.org (Michael Groshart)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Fun w/DateStamp
  5. Message-ID: <56.2a9abc1c@ivgate>
  6. Date: 25 Aug 92 01:09:09 CST
  7. Reply-To: michael.groshart@oaminet.omahug.org
  8. Organization: Omaha Amiga Net, Omaha
  9. Sender: news@ivgate.omahug.org (UUscan 1.10)
  10. Followup-To: comp.sys.amiga.programmer
  11. Lines: 79
  12.  
  13. In a message of <23-Aug-92 16:34:03 > Paul Kienitz (11:30102/2) wrote:
  14.  
  15.  PK> (From: paulk@terapin.com (Paul Kienitz)) (Organization: BBS)
  16.  
  17.  >> I need to deduce the current date.  DateStamp does the trick, of
  18.  >> course, but how useful is the number of days since Jan. 1, 1978??? Does
  19.  >> anyone know of a function or #define in the .h files somewhere that
  20.  >> translates this cryptic "internal format" into something humans use?
  21.  
  22.  PK> Here is a sample function from a program of mine ...  if the RawDoFmt
  23.  PK> calls are confusing, just pretend that they are funny-looking
  24.  PK> sprintf()s.
  25.  
  26. (Paul's example deleted)
  27.  
  28. This is another possible solution...
  29.  
  30. /***************************************************************************/
  31.  
  32. static void put_ch_proc(void)
  33. {
  34. #asm
  35.     move.b    d0,(a3)+
  36. #endasm
  37. }
  38.  
  39. void raw_do_fmt(char *string,char *format, ...)
  40. {
  41.     RawDoFmt(format,&format + 1,put_ch_proc,string);
  42. }
  43.  
  44. /***************************************************************************/
  45.  
  46. short days[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  47. char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
  48. char datefmt[] = "%02d %.3s %04d  %02d:%02d:%02d";
  49.  
  50. #define LEAP(y)    (!((y)%4)&&(((y)%100)||!((y)%400))) /* :-) */
  51.  
  52. void stamp_to_str(struct DateStamp *stamp,char *string)
  53. {
  54.     long xyzzy;
  55.     short year,day,*d,hour,min,sec;
  56.     char *month = months;
  57.  
  58.     xyzzy = (stamp->ds_Days + 1) * 100;
  59.     year = (xyzzy / 36525) + 1978;
  60.     day = (xyzzy % 36525 + 50) / 100;
  61.  
  62.     days[1] = 28 + LEAP(year);    /* fudge factor */
  63.  
  64.     for (d = days ; *d < day ; d++)
  65.     {
  66.         day -= *d;
  67.         month += 3;
  68.     }
  69.  
  70.     hour = stamp->ds_Minute / 60;
  71.     min = stamp->ds_Minute % 60;
  72.     sec = stamp->ds_Tick / TICKS_PER_SECOND;
  73.  
  74.     raw_do_fmt(string,datefmt,day,month,year,hour,min,sec);
  75. }
  76.  
  77. /***************************************************************************/
  78.  
  79. Pass stamp_to_str() pointers to a DateStamp and string (22 chars) to
  80. receive the result.
  81.  
  82.  
  83.        __
  84.       ///
  85.  __  ///   Amiga Users of the Heartland
  86.  \\\///
  87.   \XX/  michael.groshart@hottub.omahug.org
  88. ---
  89.  * Origin: "This Island Earth" -=*=- Omaha.NE.USA (1:285/30.52)
  90. SEEN-BY: 280/304 285/1 30 5010/1 
  91.  
  92.