// // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // time.cfa -- // // Author : Peter A. Buhr // Created On : Tue Mar 27 17:24:56 2018 // Last Modified By : Peter A. Buhr // Last Modified On : Tue Nov 6 18:01:45 2018 // Update Count : 17 // #include "time.hfa" #include int main() { Duration d1 = 3`h, d2 = 2`s, d3 = 3.375`s, d4 = 12`s, d5 = 1`s + 10_000`ns; sout | d1 | d2 | d3 | d4 | d5 | endl; int i; d1 = 0; sout | d1 | d2 | d3 | endl; d1 = 7`s; d3 = d2 = d1; sout | d1 | d2 | d3 | endl; d1 = d1 + d2; sout | d1 | endl; sout | d1 == 7`s | d1 == d2 | d1 == 0 | endl; sout | div( 7`s, 2`s ) | endl; sout | endl; Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 }; sout | t | endl; t = t + d1; sout | t | t.tv | endl; Time t1 = (timespec){ 104_414, 10_000_000 }; sout | t1 | t1.tv | endl; sout | t - t | t + d5 | t.tv | endl; char buf[16]; sout | "yy/mm/dd" | [t, buf]`ymd; // shared buf => separate calls sout | "mm/dd/yy" | mm_dd_yy( t, buf ); strftime( buf, 16, "%D", t ); // %D => mm/dd/yy sout | "mm/dd/yy" | buf; sout | "dd/yy/mm" | [t, buf]`dmy | endl; Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 }; sout | t2 | t2.tv | endl | t3 | t3.tv | endl; sout | endl; // Clock Newfoundland = { -3.5`h }, PST = { -8`h }; // distance from GMT (UTC) // sout | "Clock Resolution" | getRes() | endl // | "Newfoundland" | getTime( Newfoundland ) | endl // | "local" | getTime() | endl // | "local nsec" | getTimeNsec() | endl // | "PST" | PST() | endl; // getTime short form // sout | endl; // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4 Duration s = 1`h + 2 * 10`m + 70`s / 10; sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds" | endl; sout | "Dividing that by 2 minutes gives" | s / 2`m | endl; sout | "Dividing that by 2 gives" | s / 2 | "seconds\n"; sout | s | "seconds is" | s`h | "hours," | (s % 1`h)`m | "minutes," | (s % 1`m)`s | "seconds" | endl; } // main // Local Variables: // // mode: c // // tab-width: 4 // // compile-command: "cfa time.cfa" // // End: //