home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE50.TAR / mbase / dox / time.dox < prev    next >
Encoding:
Text File  |  1992-10-02  |  3.8 KB  |  89 lines

  1. Time/Date Functions                                               MetalBase 5.0
  2. -------------------------------------------------------------------------------
  3.  
  4. MetalBase handles time and date rather cleanly.  Two new types have been
  5. defined, mb_time and mb_date ... each is actually a parsed-out long, so they
  6. may be passed and returned by value as well as by reference.  There are several
  7. functions available for use with date and time fields (note that {struct tm *}
  8. is a system-supplied structure, and many many many functions are available for
  9. its use, completely independant of MetalBase):
  10.  
  11.    mb_date tmtodate (struct tm *)
  12.       If the argument passed is a valid {struct tm*} pointer, its information
  13.       is converted to mb_date format, and the new variable returned.  If the
  14.       pointer is NULL, the current date is returned.
  15.  
  16.    mb_time tmtotime (struct tm *)
  17.       If the argument passed is a valid {struct tm*} pointer, its information
  18.       is converted to mb_time format, and the new variable returned.  If the
  19.       pointer is NULL, the current time is returned.
  20.  
  21.    struct tm *datetimetotm (mb_date, mb_time)
  22.       If the arguments passed represent valid dates and times, a static local
  23.       variable is filled out to conform to {struct tm*} conventions and
  24.       returned.  If either component is zero, that component is replaced by
  25.       the current date or time.
  26.  
  27. Note that these functions have been #define'd to the following equivalents
  28. as well:
  29.  
  30.       mb_date    curdate();
  31.          Returns the current date (assign with "mb_date x = curdate()" or
  32.          whatever strikes your fancy).
  33.  
  34.       mb_time    curtime();
  35.          Returns the current time.
  36.  
  37.       struct tm *curdatetime();
  38.          Returns the curent date and time in a {struct tm *} structure.
  39.  
  40. There are also two format functions:
  41.  
  42.    char *fmt_date (mb_date, opt)
  43.       The date does _not_ default to the current date if it ==0L.  This command
  44.       returns a pointer to a static local character array, in which the date
  45.       represented will be formated to one of the following conventions:
  46.           opt:           format:
  47.          default          mm/dd/yyyy
  48.            1              mm/dd/yy
  49.            2              yymmdd
  50.       Note that we're approaching 2000, so I don't suggest using mm/dd/yy or
  51.       yymmdd... just a personal peeve.  Not that my code will be around that
  52.       long or anything, but it's only what, 8 years away?
  53.  
  54.    char *fmt_time (mb_time, opt)
  55.       The time does _not_ default to the current time if it ==0L.  This command
  56.       returns a pointer to a static local character array, in which the time
  57.       represented will be formated to one of the following conventions:
  58.           opt:           format:
  59.          default          hh:mm:ss   24-hour
  60.            1              hh:mm xx   where "xx" == "am" or "pm"
  61.            2              hh:mm      24-hour
  62.  
  63. And, accordingly, there are two scanning functions:
  64.  
  65.    mb_date scn_date (char *)
  66.       The string must contain a date, which may be in any of the formats
  67.       supported by fmt_date, and will be scanned appropriately into an
  68.       mb_date structure.  Note that this function assumes the separator
  69.       WILL BE '/' ... if you want hyphens as well, you'll have to add
  70.       that.
  71.  
  72.    mb_time scn_time (char *)
  73.       The string must contain a time, which may be in any of the formats
  74.       supported by fmt_time, and will be scanned appropriately into an
  75.       mb_time structure.
  76.  
  77. There is also a function to find the number of seconds that have elapsed since
  78. a given mb_time:
  79.    long   elap_t (mb_time)
  80. If you pass it 0L, it will return the number of seconds since midnight.
  81.  
  82. You can simulate a timer by doing something like this:
  83.          mb_time  a;
  84.          a = curtime();   /* Start timer */
  85.          for (;;)
  86.             printf ("It's been %ld seconds\n", elap_t(a));
  87. Rather useful at times. :)  Ha!  Times!  A pun!  Get it?  Hooo...
  88.  
  89.