home *** CD-ROM | disk | FTP | other *** search
- /*
- tmvalid.c 2/7/87
-
- % Time and date validation functions
-
- Written by John Cooke.
-
- OWL 1.2
- Copyright (c) 1986-1989, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 8/07/89 jmd Split from cstime.c
-
- 3/28/90 jmd ansi-fied
- 8/01/90 ted moved to OWL; include oaktime.h not cstime.h.
- 9/21/90 pmcm made time_result and result OGLOBAL
- */
-
- #include "oakhead.h"
-
- #include <time.h>
- #include "oaktime.h"
-
- /** global time data **/
-
- OGLOBAL int tm_daytab[2][13] = { /* K & R pg 104 */
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
- };
-
- OGLOBAL struct tm time_result;
- OGLOBAL struct tm *result;
-
- boolean tm_IsTimeValid(struct tm *t)
- /*
- Checks if time portion of a tm structure is valid.
- */
- {
- if ((t->tm_sec < 0 || t->tm_sec > 59) ||
- (t->tm_min < 0 || t->tm_min > 59) ||
- (t->tm_hour < 0 || t->tm_hour > 23) ) {
-
- return (FALSE);
- }
-
- return(TRUE);
- }
-
- boolean tm_IsDateValid(struct tm *t)
- /*
- Checks if the date portion of a tm structure is valid.
- mday == mon == year == 0 returns TRUE.
- */
- {
- if (t->tm_mday == 0 && t->tm_mon == 0 && t->tm_year == 0) {
- return (TRUE);
- }
-
- if ((t->tm_mon < 0 || t->tm_mon > 11) ||
- (t->tm_year < 0) ||
- (t->tm_mday < 1 || t->tm_mday > tm_daytab[tm_LeapYear(t->tm_year)][t->tm_mon])) {
- return (FALSE);
- }
-
- return(TRUE);
- }
-
- int tm_LeapYear(int year)
- /*
- returns 1 if year is a leap year, 0 if it isn't
- */
- {
- if (year%4 == 0 && year%100 != 0 || year%400 == 0) {
- return(1);
- }
-
- return(0);
- }
-
-