1 | #include "Time.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | int main(int, char **)
|
---|
8 | {
|
---|
9 | // Print the local time in the default representation of cout
|
---|
10 | cout << endl;
|
---|
11 | cout << "Local Time: " << Time(Time::local) << endl;
|
---|
12 |
|
---|
13 | // Print UTC in several different representations
|
---|
14 | Time utc;
|
---|
15 | cout << "Universal CT: " << utc << endl;
|
---|
16 | cout << "User defined: " << Time::fmt("%Y=%m=%d %H=%M=%S.%f") << utc << endl;
|
---|
17 | cout << "SQL-format: " << Time::sql << utc << endl;
|
---|
18 | cout << "ISO-format: " << Time::iso << utc << endl;
|
---|
19 | cout << "Default: " << Time::reset << utc << endl;
|
---|
20 | cout << endl;
|
---|
21 |
|
---|
22 | // Copy the UTC into a stringstream and show it on the screen
|
---|
23 | stringstream str;
|
---|
24 | str << "stringstream: " << Time::sql << utc;
|
---|
25 | cout << str.str() << endl;
|
---|
26 | cout << endl;
|
---|
27 |
|
---|
28 | // Calculate the corresponsing MJD and shoud MJD and corresponding UTC
|
---|
29 | const double mjd1 = utc.Mjd();
|
---|
30 | cout << "Mjd: " << Time::sql << utc << " (" << mjd1 << ")" << endl;
|
---|
31 |
|
---|
32 | // Set utc to the previously calculated MJD
|
---|
33 | utc.Mjd(mjd1);
|
---|
34 |
|
---|
35 | // Re-calcualte MJD from this
|
---|
36 | const double mjd2 = utc.Mjd();
|
---|
37 |
|
---|
38 | // Show the newly calculated MJD and time and the difference between both
|
---|
39 | cout << "Mjd: " << Time::sql << utc << " (" << mjd2 << ")" << endl;
|
---|
40 | cout << "Diff: " << mjd1 - mjd2 << endl;
|
---|
41 | cout << endl;
|
---|
42 |
|
---|
43 | // Instantiate a Time object with an artificial time
|
---|
44 | const Time bd(1974, 9, 9, 21, 59, 42, 123456);
|
---|
45 |
|
---|
46 | // Show it in two different representations
|
---|
47 | cout << "Loc default: " << Time::def << bd << endl;
|
---|
48 | cout << "Standard: " << Time::std << bd << endl;
|
---|
49 | cout << endl;
|
---|
50 |
|
---|
51 | // Clear the stringstream contents
|
---|
52 | str.str("");
|
---|
53 |
|
---|
54 | // Stream the time in its sql representation into the stringstream
|
---|
55 | str << Time::sql << bd;
|
---|
56 |
|
---|
57 | // Stream a time from the stringstream considering an sql representation
|
---|
58 | // into a Time object
|
---|
59 | Time tm;
|
---|
60 | str >> Time::sql >> tm;
|
---|
61 |
|
---|
62 | // Output stream and interpreted time
|
---|
63 | cout << "Stream: " << str.str() << endl;
|
---|
64 | cout << "Time: " << Time::sql << tm << endl;
|
---|
65 | cout << endl;
|
---|
66 |
|
---|
67 | // Print the individual elements of the date and the time
|
---|
68 | cout << "Elements: ";
|
---|
69 | cout << tm.Y() << " " << tm.M() << " " << tm.D() << " " ;
|
---|
70 | cout << tm.h() << " " << tm.m() << " " << tm.s() << " " ;
|
---|
71 | cout << tm.us() << endl;
|
---|
72 | cout << endl;
|
---|
73 |
|
---|
74 | return 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | // **************************************************************************
|
---|
78 | /** @example time.cc
|
---|
79 |
|
---|
80 | Example for the usage of the class Time
|
---|
81 |
|
---|
82 | **/
|
---|
83 | // **************************************************************************
|
---|