Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/time.cfa

    r200fcb3 rdc8511c  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 11 21:44:03 2018
    13 // Update Count     : 22
     12// Last Modified On : Tue Nov  6 18:01:45 2018
     13// Update Count     : 17
    1414//
    1515
     
    1919int main() {
    2020        Duration d1 = 3`h, d2 = 2`s, d3 = 3.375`s, d4 = 12`s, d5 = 1`s + 10_000`ns;
    21         sout | d1 | d2 | d3 | d4 | d5;
     21        sout | d1 | d2 | d3 | d4 | d5 | endl;
    2222        int i;
    2323        d1 = 0;
    24         sout | d1 | d2 | d3;
     24        sout | d1 | d2 | d3 | endl;
    2525        d1 = 7`s;
    2626        d3 = d2 = d1;
    27         sout | d1 | d2 | d3;
     27        sout | d1 | d2 | d3 | endl;
    2828        d1 = d1 + d2;
    29         sout | d1;
    30         sout | d1 == 7`s | d1 == d2 | d1 == 0;
    31         sout | div( 7`s, 2`s );
     29        sout | d1 | endl;
     30        sout | d1 == 7`s | d1 == d2 | d1 == 0 | endl;
     31        sout | div( 7`s, 2`s ) | endl;
     32        sout | endl;
    3233
    3334        Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 };
    34         sout | t;
     35        sout | t | endl;
    3536        t = t + d1;
    36         sout | t | t.tv;
     37        sout | t | t.tv | endl;
    3738        Time t1 = (timespec){ 104_414, 10_000_000 };
    38         sout | t1 | t1.tv;
    39         sout | t - t  | t + d5 | t.tv;
     39        sout | t1 | t1.tv | endl;
     40        sout | t - t  | t + d5 | t.tv | endl;
    4041        char buf[16];
    41         sout | "yy/mm/dd" | [t, buf]`ymd | nonl;                        // shared buf => separate calls
    42         sout | "mm/dd/yy" | mm_dd_yy( t, buf ) | nonl;
     42        sout | "yy/mm/dd" | [t, buf]`ymd;                                       // shared buf => separate calls
     43        sout | "mm/dd/yy" | mm_dd_yy( t, buf );
    4344        strftime( buf, 16, "%D", t );                                           // %D => mm/dd/yy
    44         sout | "mm/dd/yy" | buf | nonl;
    45         sout | "dd/yy/mm" | [t, buf]`dmy;
     45        sout | "mm/dd/yy" | buf;
     46        sout | "dd/yy/mm" | [t, buf]`dmy | endl;
    4647        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
    47         sout | t2 | t2.tv | nl | t3 | t3.tv;
     48        sout | t2 | t2.tv | endl | t3 | t3.tv | endl;
     49        sout | endl;
    4850
    4951        // Clock Newfoundland = { -3.5`h }, PST = { -8`h };     // distance from GMT (UTC)
    50         // sout | "Clock Resolution" | getRes()
    51         //       | "Newfoundland" | getTime( Newfoundland )
    52         //       | "local" | getTime()
    53         //       | "local nsec" | getTimeNsec()
    54         //       | "PST" | PST();                                                               // getTime short form
    55         // sout;
     52        // sout | "Clock Resolution" | getRes() | endl
     53        //       | "Newfoundland" | getTime( Newfoundland ) | endl
     54        //       | "local" | getTime() | endl
     55        //       | "local nsec" | getTimeNsec() | endl
     56        //       | "PST" | PST() | endl;                                                // getTime short form
     57        // sout | endl;
    5658
    5759        // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
    5860        Duration s = 1`h + 2 * 10`m + 70`s / 10;
    59         sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds";
    60         sout | "Dividing that by 2 minutes gives" | s / 2`m;
    61         sout | "Dividing that by 2 gives" | s / 2 | "seconds";
    62         sout | s | "seconds is" | s`h | "hours," | (s % 1`h)`m | "minutes," | (s % 1`m)`s | "seconds";
     61        sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds" | endl;
     62        sout | "Dividing that by 2 minutes gives" | s / 2`m | endl;
     63        sout | "Dividing that by 2 gives" | s / 2 | "seconds\n";
     64        sout | s | "seconds is" | s`h | "hours," | (s % 1`h)`m | "minutes," | (s % 1`m)`s | "seconds" | endl;
    6365} // main
    6466
Note: See TracChangeset for help on using the changeset viewer.