Changes in libcfa/src/time.cfa [e0c235c:ff2a33e]
- File:
-
- 1 edited
-
libcfa/src/time.cfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/time.cfa
re0c235c rff2a33e 10 10 // Created On : Tue Mar 27 13:33:14 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Jan 5 17:27:40 202013 // Update Count : 6 912 // Last Modified On : Sat Jul 13 08:41:55 2019 13 // Update Count : 65 14 14 // 15 15 … … 33 33 forall( dtype ostype | ostream( ostype ) ) { 34 34 ostype & ?|?( ostype & os, Duration dur ) with( dur ) { 35 (ostype &)(os | t n/ TIMEGRAN); // print seconds36 long int ns = (t n < 0 ? -tn : tn) % TIMEGRAN; // compute nanoseconds35 (ostype &)(os | tv / TIMEGRAN); // print seconds 36 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 37 37 if ( ns != 0 ) { // some ? 38 38 char buf[16]; … … 52 52 53 53 #ifdef __CFA_DEBUG__ 54 static void tabort( int year, int month, int day, int hour, int min, int sec, int 64_tnsec ) {54 static void tabort( int year, int month, int day, int hour, int min, int sec, int nsec ) { 55 55 abort | "Attempt to create Time( year=" | year | "(>=1970), month=" | month | "(1-12), day=" | day | "(1-31), hour=" | hour | "(0-23), min=" | min | "(0-59), sec=" | sec 56 | "(0-60), nsec=" | nsec | "(0-999_999_999), which is not in the range 00:00:00 UTC, January 1, 1970 to 03:14:07 UTC, January 19, 2038, where month and day have 1 origin.";56 | "(0-60), nsec=" | nsec | "(0-999_999_999), which exceeds range 00:00:00 UTC, January 1, 1970 to 03:14:07 UTC, January 19, 2038."; 57 57 } // tabort 58 58 #endif // __CFA_DEBUG__ 59 59 60 void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int 64_tnsec ) with( time ) {60 void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ) with( time ) { 61 61 tm tm; 62 62 63 // Values can be in any range (+/-) but result must be in the epoch.63 tm.tm_isdst = -1; // let mktime determine if alternate timezone is in effect 64 64 tm.tm_year = year - 1900; // mktime uses 1900 as its starting point 65 // Make month in range 1-12 to match with day. 65 #ifdef __CFA_DEBUG__ 66 if ( month < 1 || 12 < month ) { 67 tabort( year, month, day, hour, min, sec, nsec ); 68 } // if 69 #endif // __CFA_DEBUG__ 66 70 tm.tm_mon = month - 1; // mktime uses range 0-11 71 #ifdef __CFA_DEBUG__ 72 if ( day < 1 || 31 < day ) { 73 tabort( year, month, day, hour, min, sec, nsec ); 74 } // if 75 #endif // __CFA_DEBUG__ 67 76 tm.tm_mday = day; // mktime uses range 1-31 68 77 tm.tm_hour = hour; 69 78 tm.tm_min = min; 70 79 tm.tm_sec = sec; 71 tm.tm_isdst = -1; // let mktime determine if alternate timezone is in effect72 80 time_t epochsec = mktime( &tm ); 73 81 #ifdef __CFA_DEBUG__ 74 if ( epochsec <= (time_t)-1 ) { // MUST BE LESS THAN OR EQUAL!82 if ( epochsec == (time_t)-1 ) { 75 83 tabort( year, month, day, hour, min, sec, nsec ); 76 84 } // if 77 85 #endif // __CFA_DEBUG__ 78 t n= (int64_t)(epochsec) * TIMEGRAN + nsec; // convert to nanoseconds86 tv = (int64_t)(epochsec) * TIMEGRAN + nsec; // convert to nanoseconds 79 87 #ifdef __CFA_DEBUG__ 80 if ( t n> 2147483647LL * TIMEGRAN ) { // between 00:00:00 UTC, January 1, 1970 and 03:14:07 UTC, January 19, 2038.88 if ( tv > 2147483647LL * TIMEGRAN ) { // between 00:00:00 UTC, January 1, 1970 and 03:14:07 UTC, January 19, 2038. 81 89 tabort( year, month, day, hour, min, sec, nsec ); 82 90 } // if … … 85 93 86 94 char * yy_mm_dd( Time time, char * buf ) with( time ) { 87 time_t s = t n/ TIMEGRAN;95 time_t s = tv / TIMEGRAN; 88 96 tm tm; 89 97 gmtime_r( &s, &tm ); // tm_mon <= 11, tm_mday <= 31 … … 100 108 101 109 char * mm_dd_yy( Time time, char * buf ) with( time ) { 102 time_t s = t n/ TIMEGRAN;110 time_t s = tv / TIMEGRAN; 103 111 tm tm; 104 112 gmtime_r( &s, &tm ); // tm_mon <= 11, tm_mday <= 31 … … 115 123 116 124 char * dd_mm_yy( Time time, char * buf ) with( time ) { 117 time_t s = t n/ TIMEGRAN;125 time_t s = tv / TIMEGRAN; 118 126 tm tm; 119 127 gmtime_r( &s, &tm ); // tm_mon <= 11, tm_mday <= 31 … … 130 138 131 139 size_t strftime( char * buf, size_t size, const char * fmt, Time time ) with( time ) { 132 time_t s = t n/ TIMEGRAN;140 time_t s = tv / TIMEGRAN; 133 141 tm tm; 134 142 gmtime_r( &s, &tm ); … … 139 147 ostype & ?|?( ostype & os, Time time ) with( time ) { 140 148 char buf[32]; // at least 26 141 time_t s = t n/ TIMEGRAN;149 time_t s = tv / TIMEGRAN; 142 150 ctime_r( &s, (char *)&buf ); // 26 characters: "Wed Jun 30 21:49:08 1993\n" 143 151 buf[24] = '\0'; // remove trailing '\n' 144 long int ns = (t n < 0 ? -tn : tn) % TIMEGRAN; // compute nanoseconds152 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN; // compute nanoseconds 145 153 if ( ns == 0 ) { // none ? 146 154 (ostype &)(os | buf); // print date/time/year
Note:
See TracChangeset
for help on using the changeset viewer.