Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/time.cfa

    re0c235c rff2a33e  
    1010// Created On       : Tue Mar 27 13:33:14 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jan  5 17:27:40 2020
    13 // Update Count     : 69
     12// Last Modified On : Sat Jul 13 08:41:55 2019
     13// Update Count     : 65
    1414//
    1515
     
    3333forall( dtype ostype | ostream( ostype ) ) {
    3434        ostype & ?|?( ostype & os, Duration dur ) with( dur ) {
    35                 (ostype &)(os | tn / TIMEGRAN);                                 // print seconds
    36                 long int ns = (tn < 0 ? -tn : tn) % TIMEGRAN;   // compute nanoseconds
     35                (ostype &)(os | tv / TIMEGRAN);                                 // print seconds
     36                long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;   // compute nanoseconds
    3737                if ( ns != 0 ) {                                                                // some ?
    3838                        char buf[16];
     
    5252
    5353#ifdef __CFA_DEBUG__
    54 static void tabort( int year, int month, int day, int hour, int min, int sec, int64_t nsec ) {
     54static void tabort( int year, int month, int day, int hour, int min, int sec, int nsec ) {
    5555        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.";
    5757} // tabort
    5858#endif // __CFA_DEBUG__
    5959
    60 void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int64_t nsec ) with( time ) {
     60void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ) with( time ) {
    6161        tm tm;
    6262
    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
    6464        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__
    6670        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__
    6776        tm.tm_mday = day;                                                                       // mktime uses range 1-31
    6877        tm.tm_hour = hour;
    6978        tm.tm_min = min;
    7079        tm.tm_sec = sec;
    71         tm.tm_isdst = -1;                                                                       // let mktime determine if alternate timezone is in effect
    7280        time_t epochsec = mktime( &tm );
    7381#ifdef __CFA_DEBUG__
    74         if ( epochsec <= (time_t)-1 ) {                                         // MUST BE LESS THAN OR EQUAL!
     82        if ( epochsec == (time_t)-1 ) {
    7583                tabort( year, month, day, hour, min, sec, nsec );
    7684        } // if
    7785#endif // __CFA_DEBUG__
    78         tn = (int64_t)(epochsec) * TIMEGRAN + nsec;                     // convert to nanoseconds
     86        tv = (int64_t)(epochsec) * TIMEGRAN + nsec;                     // convert to nanoseconds
    7987#ifdef __CFA_DEBUG__
    80         if ( tn > 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.
    8189                tabort( year, month, day, hour, min, sec, nsec );
    8290        } // if
     
    8593
    8694char * yy_mm_dd( Time time, char * buf ) with( time ) {
    87         time_t s = tn / TIMEGRAN;
     95        time_t s = tv / TIMEGRAN;
    8896        tm tm;
    8997        gmtime_r( &s, &tm );                                                            // tm_mon <= 11, tm_mday <= 31
     
    100108
    101109char * mm_dd_yy( Time time, char * buf ) with( time ) {
    102         time_t s = tn / TIMEGRAN;
     110        time_t s = tv / TIMEGRAN;
    103111        tm tm;
    104112        gmtime_r( &s, &tm );                                                            // tm_mon <= 11, tm_mday <= 31
     
    115123
    116124char * dd_mm_yy( Time time, char * buf ) with( time ) {
    117         time_t s = tn / TIMEGRAN;
     125        time_t s = tv / TIMEGRAN;
    118126        tm tm;
    119127        gmtime_r( &s, &tm );                                                            // tm_mon <= 11, tm_mday <= 31
     
    130138
    131139size_t strftime( char * buf, size_t size, const char * fmt, Time time ) with( time ) {
    132         time_t s = tn / TIMEGRAN;
     140        time_t s = tv / TIMEGRAN;
    133141        tm tm;
    134142        gmtime_r( &s, &tm );
     
    139147        ostype & ?|?( ostype & os, Time time ) with( time ) {
    140148                char buf[32];                                                                   // at least 26
    141                 time_t s = tn / TIMEGRAN;
     149                time_t s = tv / TIMEGRAN;
    142150                ctime_r( &s, (char *)&buf );                                    // 26 characters: "Wed Jun 30 21:49:08 1993\n"
    143151                buf[24] = '\0';                                                                 // remove trailing '\n'
    144                 long int ns = (tn < 0 ? -tn : tn) % TIMEGRAN;   // compute nanoseconds
     152                long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;   // compute nanoseconds
    145153                if ( ns == 0 ) {                                                                // none ?
    146154                        (ostype &)(os | buf);                                           // print date/time/year
Note: See TracChangeset for help on using the changeset viewer.