home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / TMVALID.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-21  |  1.6 KB  |  82 lines

  1. /*
  2.     tmvalid.c    2/7/87
  3.  
  4.     % Time and date validation functions
  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.      3/28/90 jmd    ansi-fied
  17.      8/01/90 ted    moved to OWL; include oaktime.h not cstime.h.
  18.      9/21/90 pmcm    made time_result and result OGLOBAL
  19. */
  20.  
  21. #include "oakhead.h"
  22.  
  23. #include <time.h>
  24. #include "oaktime.h"
  25.  
  26. /** global time data **/
  27.  
  28. OGLOBAL int tm_daytab[2][13] = {      /* K & R pg 104 */
  29.     {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
  30.     {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
  31. };
  32.  
  33. OGLOBAL struct tm time_result;
  34. OGLOBAL struct tm *result;
  35.  
  36. boolean tm_IsTimeValid(struct tm *t)
  37. /*
  38.     Checks if time portion of a tm structure is valid.
  39. */
  40. {
  41.     if ((t->tm_sec < 0 || t->tm_sec > 59) ||
  42.         (t->tm_min < 0 || t->tm_min > 59) ||
  43.         (t->tm_hour < 0 || t->tm_hour > 23) ) {
  44.  
  45.         return (FALSE);
  46.     }
  47.  
  48.     return(TRUE);
  49. }
  50.  
  51. boolean tm_IsDateValid(struct tm *t)
  52. /*
  53.     Checks if the date portion of a tm structure is valid.
  54.         mday == mon == year == 0 returns TRUE.
  55. */
  56. {
  57.     if (t->tm_mday == 0 && t->tm_mon == 0 && t->tm_year == 0) {
  58.         return (TRUE);
  59.     }
  60.  
  61.     if ((t->tm_mon < 0 || t->tm_mon > 11) ||
  62.         (t->tm_year < 0) ||
  63.         (t->tm_mday < 1 || t->tm_mday > tm_daytab[tm_LeapYear(t->tm_year)][t->tm_mon])) {
  64.         return (FALSE);
  65.     }
  66.  
  67.     return(TRUE);
  68. }
  69.  
  70. int tm_LeapYear(int year)
  71. /*
  72.     returns 1 if year is a leap year, 0 if it isn't
  73. */
  74. {
  75.     if (year%4 == 0 && year%100 != 0 || year%400 == 0) {
  76.         return(1);
  77.     }
  78.  
  79.     return(0);
  80. }
  81.  
  82.