home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / TMNOW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  1.8 KB  |  100 lines

  1. /*
  2.     tmnow.c    2/7/87
  3.  
  4.     % tm_Now, tm_Copy, tm_Zero
  5.  
  6.     Written by John Cooke.
  7.  
  8.     OWL 1.2
  9.     Copyright (c) 1986-1989, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      8/07/89 jmd    Split from cstime.c
  15.  
  16.     10/20/89 jmd    re-wrote tm_Now (no longer uses global data)
  17.      3/28/90 jmd    ansi-fied
  18.      8/01/90 ted    Moved to OWL; include oaktime.h not cstime.h.
  19. */
  20.  
  21. #include "oakhead.h"
  22.  
  23. #include <time.h>
  24. #include "oaktime.h"
  25.  
  26. struct tm *tm_Now(struct tm *t)
  27. /*
  28. DESCRIPTION:
  29.     The tm_Now function places the current time in t.
  30. RETURNS:
  31.     Returns t or NULL if t = NULL.
  32. */
  33. {
  34.     TIME_T ltime;
  35.     struct tm *tresult;
  36.  
  37.     if (t != NULL) {
  38.  
  39.         /* get the current time */
  40.         time(<ime);
  41.         tresult = localtime(<ime);
  42.  
  43.         /* copy time into t */
  44.         tm_Copy(t, tresult);
  45.  
  46.         /* adjust the year */
  47.         t->tm_year += 1900;
  48.     }
  49.  
  50.     return(t);
  51. }
  52.  
  53. struct tm *tm_Copy(struct tm *dest, struct tm *source)
  54. /*
  55. DESCRIPTION:
  56.     The tm_Copy function copies the time in source to dest.
  57. RETURNS:
  58.     Returns dest or NULL if either dest or source is
  59.     equal to NULL.
  60. */
  61. {
  62.     if (dest == NULL || source == NULL) {
  63.         return(NULL);
  64.     }
  65.  
  66.     dest->tm_sec     = source->tm_sec;
  67.     dest->tm_min     = source->tm_min;
  68.     dest->tm_hour    = source->tm_hour;
  69.     dest->tm_mday     = source->tm_mday;
  70.     dest->tm_mon     = source->tm_mon;
  71.     dest->tm_year     = source->tm_year;
  72.     dest->tm_wday     = source->tm_wday;
  73.     dest->tm_yday     = source->tm_yday;
  74.     dest->tm_isdst    = source->tm_isdst;
  75.  
  76.     return(dest);
  77. }
  78.  
  79.  
  80. struct tm *tm_Zero(struct tm *t)
  81. /*
  82. DESCRIPTION:
  83.     The tm_Zero function sets all the elements of t to 0.
  84. RETURNS:
  85.     Returns t.
  86. */
  87. {
  88.     t->tm_sec     = 0;
  89.     t->tm_min     = 0;
  90.     t->tm_hour    = 0;
  91.     t->tm_mday     = 0;
  92.     t->tm_mon     = 0;
  93.     t->tm_year     = 0;
  94.     t->tm_wday     = 0;
  95.     t->tm_yday     = 0;
  96.     t->tm_isdst    = 0;
  97.  
  98.     return(t);
  99. }
  100.