source: tests/time.cfa @ 0f3d844

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0f3d844 was e0c235c, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

move clock.hfa into time.hfa, add getCPUTime, rename duration and time field to "tn", update mktime code

  • Property mode set to 100644
File size: 2.4 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//
[dc8511c]7// time.cfa --
[73abe95]8//
[43725bd]9// Author           : Peter A. Buhr
10// Created On       : Tue Mar 27 17:24:56 2018
11// Last Modified By : Peter A. Buhr
[e0c235c]12// Last Modified On : Sun Jan  5 18:27:37 2020
13// Update Count     : 34
[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;
[200fcb3]21        sout | d1 | d2 | d3 | d4 | d5;
[43725bd]22        d1 = 0;
[200fcb3]23        sout | d1 | d2 | d3;
[43725bd]24        d1 = 7`s;
25        d3 = d2 = d1;
[200fcb3]26        sout | d1 | d2 | d3;
[43725bd]27        d1 = d1 + d2;
[200fcb3]28        sout | d1;
29        sout | d1 == 7`s | d1 == d2 | d1 == 0;
30        sout | div( 7`s, 2`s );
[5ea5b28]31        sout | nl;
[43725bd]32
33        Time t = { 1970, 1, 2, 0, 0, 0, 10_000_000 };
[200fcb3]34        sout | t;
[43725bd]35        t = t + d1;
[e0c235c]36        sout | t | t`ns;
[8eb2018]37        Time t1 = (timespec){ 104_414, 10_000_000 };
[e0c235c]38        sout | t1 | t1`ns;
39        sout | t - t  | t + d5 | t`ns;
40        char buf[64];
[200fcb3]41        sout | "yy/mm/dd" | [t, buf]`ymd | nonl;                        // shared buf => separate calls
42        sout | "mm/dd/yy" | mm_dd_yy( t, buf ) | nonl;
[43725bd]43        strftime( buf, 16, "%D", t );                                           // %D => mm/dd/yy
[200fcb3]44        sout | "mm/dd/yy" | buf | nonl;
45        sout | "dd/yy/mm" | [t, buf]`dmy;
[8eb2018]46        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
[e0c235c]47        sout | t2 | t2`ns | nl | t3 | t3`ns;
[5ea5b28]48        sout | nl;
[43725bd]49
50        // Clock Newfoundland = { -3.5`h }, PST = { -8`h };     // distance from GMT (UTC)
[200fcb3]51        // sout | "Clock Resolution" | getRes()
52        //       | "Newfoundland" | getTime( Newfoundland )
53        //       | "local" | getTime()
54        //       | "local nsec" | getTimeNsec()
55        //       | "PST" | PST();                                                               // getTime short form
[5ea5b28]56        // sout | nl;
[43725bd]57
58        // http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
59        Duration s = 1`h + 2 * 10`m + 70`s / 10;
[200fcb3]60        sout | "1 hour + 2*10 min + 70/10 sec = " | s | "seconds";
61        sout | "Dividing that by 2 minutes gives" | s / 2`m;
62        sout | "Dividing that by 2 gives" | s / 2 | "seconds";
63        sout | s | "seconds is" | s`h | "hours," | (s % 1`h)`m | "minutes," | (s % 1`m)`s | "seconds";
[e0c235c]64
65    t1 = (Time){ 2020, 1, 5, 9, 0, 0, 100000000000LL };
66    t2 = (Time){ 1969, 13, 5, 9 };
67    t3 = (Time){ 1970, 25, 366, 48, 120, -120, 60000000000LL };
68    strftime( buf, 128, "%Y %b %e %H:%M:%S (GMT)", t1 );
69    sout | buf;
70    strftime( buf, 128, "%Y %b %e %H:%M:%S (GMT)", t2 );
71    sout | buf;
72    strftime( buf, 128, "%Y %b %e %H:%M:%S (GMT)", t3 );
73    sout | buf;
[43725bd]74} // main
75
76// Local Variables: //
77// mode: c //
78// tab-width: 4 //
[dc8511c]79// compile-command: "cfa time.cfa" //
[43725bd]80// End: //
Note: See TracBrowser for help on using the repository browser.