source: tests/time.c @ 933933c

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 933933c was ef2eade, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

fixed math tests which differed per platform

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[73abe95]1//
[43725bd]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.
[73abe95]6//
7// time.c --
8//
[43725bd]9// Author           : Peter A. Buhr
10// Created On       : Tue Mar 27 17:24:56 2018
11// Last Modified By : Peter A. Buhr
[d35abc2]12// Last Modified On : Fri Apr  6 11:27:23 2018
13// Update Count     : 16
[73abe95]14//
[43725bd]15
[58b6d1b]16#include "time.hfa"
[73abe95]17#include <fstream.hfa>
[43725bd]18
19int main() {
[ef2eade]20        Duration d1 = 3`h, d2 = 2`s, d3 = 3.375`s, d4 = 12`s, d5 = 1`s + 10_000`ns;
[43725bd]21        sout | d1 | d2 | d3 | d4 | d5 | endl;
22        int i;
23        d1 = 0;
24        sout | d1 | d2 | d3 | endl;
25        d1 = 7`s;
26        d3 = d2 = d1;
27        sout | d1 | d2 | d3 | endl;
28        d1 = d1 + d2;
29        sout | d1 | endl;
30        sout | d1 == 7`s | d1 == d2 | d1 == 0 | endl;
[d35abc2]31        sout | div( 7`s, 2`s ) | endl;
[43725bd]32        sout | endl;
33
34        Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 };
35        sout | t | endl;
36        t = t + d1;
[8eb2018]37        sout | t | t.tv | endl;
38        Time t1 = (timespec){ 104_414, 10_000_000 };
39        sout | t1 | t1.tv | endl;
40        sout | t - t  | t + d5 | t.tv | endl;
[43725bd]41        char buf[16];
42        sout | "yy/mm/dd" | [t, buf]`ymd;                                       // shared buf => separate calls
43        sout | "mm/dd/yy" | mm_dd_yy( t, buf );
44        strftime( buf, 16, "%D", t );                                           // %D => mm/dd/yy
45        sout | "mm/dd/yy" | buf;
46        sout | "dd/yy/mm" | [t, buf]`dmy | endl;
[8eb2018]47        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
48        sout | t2 | t2.tv | endl | t3 | t3.tv | endl;
[43725bd]49        sout | endl;
50
51        // Clock Newfoundland = { -3.5`h }, PST = { -8`h };     // distance from GMT (UTC)
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;
58
59        // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
60        Duration s = 1`h + 2 * 10`m + 70`s / 10;
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;
65} // main
66
67// Local Variables: //
68// mode: c //
69// tab-width: 4 //
[d35abc2]70// compile-command: "cfa time.c" //
[43725bd]71// End: //
Note: See TracBrowser for help on using the repository browser.