Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/time.cfa

    ref346f7c r58b6d1b  
    1010// Created On       : Tue Mar 27 13:33:14 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 23 22:57:48 2018
    13 // Update Count     : 57
     12// Last Modified On : Sun May  6 22:26:00 2018
     13// Update Count     : 37
    1414//
    1515
     
    3131
    3232
    33 forall( dtype ostype | ostream( ostype ) ) {
    34         ostype & ?|?( ostype & os, Duration dur ) with( dur ) {
    35                 (ostype &)(os | tv / TIMEGRAN);                                 // print seconds
    36                 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;   // compute nanoseconds
    37                 if ( ns != 0 ) {                                                                // some ?
    38                         char buf[16];
    39                         (ostype &)(os | nanomsd( ns, buf ));                    // print nanoseconds
    40                 } // if
    41                 return os;
    42         } // ?|?
    43 
    44         void ?|?( ostype & os, Duration dur ) with( dur ) {
    45                 (ostype &)(os | dur); nl( os );
    46         } // ?|?
    47 } // distribution
     33forall( dtype ostype | ostream( ostype ) )
     34ostype & ?|?( ostype & os, Duration dur ) with( dur ) {
     35        os | tv / TIMEGRAN;                                                                     // print seconds
     36        long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;           // compute nanoseconds
     37        if ( ns != 0 ) {                                                                        // some ?
     38                char buf[16];
     39                os | nanomsd( ns, buf );                                                // print nanoseconds
     40        } // if
     41        return os;
     42} // ?|?
    4843
    4944
     
    142137} // strftime
    143138
    144 forall( dtype ostype | ostream( ostype ) ) {
    145         ostype & ?|?( ostype & os, Time time ) with( time ) {
    146                 char buf[32];                                                                   // at least 26
    147                 time_t s = tv / TIMEGRAN;
    148                 ctime_r( &s, (char *)&buf );                                    // 26 characters: "Wed Jun 30 21:49:08 1993\n"
    149                 buf[24] = '\0';                                                                 // remove trailing '\n'
    150                 long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;   // compute nanoseconds
    151                 if ( ns == 0 ) {                                                                // none ?
    152                         (ostype &)(os | buf);                                                   // print date/time/year
    153                 } else {
    154                         buf[19] = '\0';                                                         // truncate to "Wed Jun 30 21:49:08"
    155                         char buf2[16];
    156                         nanomsd( ns, buf2 );                                            // compute nanoseconds
    157                         (ostype &)(os | buf | buf2 | ' ' | &buf[20]);   // print date/time, nanoseconds and year
    158                 } // if
    159                 return os;
    160         } // ?|?
    161 
    162         void ?|?( ostype & os, Time time ) with( time ) {
    163                 (ostype &)(os | time); nl( os );
    164         } // ?|?
    165 } // distribution
     139forall( dtype ostype | ostream( ostype ) )
     140ostype & ?|?( ostype & os, Time time ) with( time ) {
     141        char buf[32];                                                                           // at least 26
     142        time_t s = tv / TIMEGRAN;
     143    ctime_r( &s, (char *)&buf );                                                // 26 characters: "Wed Jun 30 21:49:08 1993\n"
     144        buf[24] = '\0';                                                                         // remove trailing '\n'
     145        long int ns = (tv < 0 ? -tv : tv) % TIMEGRAN;           // compute nanoseconds
     146        if ( ns == 0 ) {                                                                        // none ?
     147                os | buf;                                                                               // print date/time/year
     148        } else {
     149                buf[19] = '\0';                                                                 // truncate to "Wed Jun 30 21:49:08"
     150                os | buf;                                                                               // print date/time
     151                char buf2[16];
     152                nanomsd( ns, buf2 );                                                    // compute nanoseconds
     153                os | buf2 | ' ' | &buf[20];                                             // print nanoseconds and year
     154        } // if
     155        return os;
     156} // ?|?
    166157
    167158// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.