|
|
1.1 ! root 1: /* ut2tm.c - time string to tm */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/psap/RCS/ut2tm.c,v 7.0 89/11/23 22:13:56 mrose Rel $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/psap/RCS/ut2tm.c,v 7.0 89/11/23 22:13:56 mrose Rel $ ! 9: * ! 10: * ! 11: * $Log: ut2tm.c,v $ ! 12: * Revision 7.0 89/11/23 22:13:56 mrose ! 13: * Release 6.0 ! 14: * ! 15: */ ! 16: ! 17: /* ! 18: * NOTICE ! 19: * ! 20: * Acquisition, use, and distribution of this module and related ! 21: * materials are subject to the restrictions of a license agreement. ! 22: * Consult the Preface in the User's Manual for the full terms of ! 23: * this agreement. ! 24: * ! 25: */ ! 26: ! 27: ! 28: /* LINTLIBRARY */ ! 29: ! 30: #include <stdio.h> ! 31: #include "psap.h" ! 32: #ifdef OSX ! 33: #include <sys/time.h> ! 34: #endif ! 35: ! 36: ! 37: #define UNYEAR(y) ((y) < 1900 || (y) > 1999 ? (y) : (y) - 1900) ! 38: ! 39: extern int dmsize[]; ! 40: ! 41: /* */ ! 42: ! 43: struct tm *ut2tm (ut) ! 44: register UTC ut; ! 45: { ! 46: static struct tm tms; ! 47: register struct tm *tm = &tms; ! 48: ! 49: bzero ((char *) tm, sizeof *tm); ! 50: ! 51: tm -> tm_sec = ut -> ut_sec; ! 52: tm -> tm_min = ut -> ut_min; ! 53: tm -> tm_hour = ut -> ut_hour; ! 54: tm -> tm_mday = ut -> ut_mday; ! 55: tm -> tm_mon = ut -> ut_mon - 1; ! 56: tm -> tm_year = UNYEAR (ut -> ut_year); ! 57: tm -> tm_wday = makewkday (ut); ! 58: tm -> tm_yday = tm -> tm_isdst = 0; ! 59: ! 60: tm -> tm_hour -= ut -> ut_zone / 60, tm -> tm_min -= ut -> ut_zone % 60; ! 61: if (tm -> tm_min < 0) ! 62: tm -> tm_hour--, tm -> tm_min += 60; ! 63: else ! 64: if (tm -> tm_min > 59) ! 65: tm -> tm_hour++, tm -> tm_min -= 60; ! 66: ! 67: /* this ignores odditites in February... */ ! 68: if (tm -> tm_hour < 0) { ! 69: tm -> tm_mday++, tm -> tm_hour += 24; ! 70: if (tm -> tm_mday > dmsize[tm -> tm_mon]) { ! 71: tm -> tm_mon++, tm -> tm_mday = 1; ! 72: if (tm -> tm_mon > 11) ! 73: tm -> tm_year++, tm -> tm_mon = 0; ! 74: } ! 75: ! 76: } ! 77: else ! 78: if (tm -> tm_hour > 23) { ! 79: tm -> tm_mday--, tm -> tm_hour -= 24; ! 80: if (tm -> tm_mday < 1) { ! 81: tm -> tm_mday = dmsize[--tm -> tm_mon]; ! 82: if (tm -> tm_mon < 0) ! 83: tm -> tm_year--, tm -> tm_mon = 11; ! 84: } ! 85: } ! 86: ! 87: return tm; ! 88: } ! 89: ! 90: /* */ ! 91: ! 92: #define dysize(y) \ ! 93: (((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366))) ! 94: ! 95: #define YEAR(y) ((y) >= 100 ? (y) : (y) + 1900) ! 96: ! 97: ! 98: static int makewkday (ut) ! 99: UTC ut; ! 100: { ! 101: int d, ! 102: mon, ! 103: year; ! 104: ! 105: mon = ut -> ut_mon; ! 106: year = YEAR (ut -> ut_year); ! 107: d = 4 + year + (year + 3) / 4; ! 108: ! 109: if (year > 1800) { ! 110: d -= (year - 1701) / 100; ! 111: d += (year - 1601) / 400; ! 112: } ! 113: if (year > 1752) ! 114: d += 3; ! 115: if (dysize (year) == 366 && mon > 3) ! 116: d++; ! 117: while (--mon) ! 118: d += dmsize[mon - 1]; ! 119: d += ut -> ut_mday - 1; ! 120: ! 121: return (d % 7); ! 122: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.