source: tests/time.cfa @ 200fcb3

aaron-thesisarm-ehcleanup-dtorsdeferred_resnjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexer
Last change on this file since 200fcb3 was 200fcb3, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

add auto newline to sout, change endl to nl

  • Property mode set to 100644
File size: 2.1 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// time.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Tue Mar 27 17:24:56 2018
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Dec 11 21:44:03 2018
13// Update Count     : 22
14//
15
16#include "time.hfa"
17#include <fstream.hfa>
18
19int main() {
20        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;
22        int i;
23        d1 = 0;
24        sout | d1 | d2 | d3;
25        d1 = 7`s;
26        d3 = d2 = d1;
27        sout | d1 | d2 | d3;
28        d1 = d1 + d2;
29        sout | d1;
30        sout | d1 == 7`s | d1 == d2 | d1 == 0;
31        sout | div( 7`s, 2`s );
32
33        Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 };
34        sout | t;
35        t = t + d1;
36        sout | t | t.tv;
37        Time t1 = (timespec){ 104_414, 10_000_000 };
38        sout | t1 | t1.tv;
39        sout | t - t  | t + d5 | t.tv;
40        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;
43        strftime( buf, 16, "%D", t );                                           // %D => mm/dd/yy
44        sout | "mm/dd/yy" | buf | nonl;
45        sout | "dd/yy/mm" | [t, buf]`dmy;
46        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
47        sout | t2 | t2.tv | nl | t3 | t3.tv;
48
49        // 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;
56
57        // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
58        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";
63} // main
64
65// Local Variables: //
66// mode: c //
67// tab-width: 4 //
68// compile-command: "cfa time.cfa" //
69// End: //
Note: See TracBrowser for help on using the repository browser.