-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
95 lines (70 loc) · 2.15 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* main.cpp
* ========
* Copyright 2013 Paul Griffiths
* Email: mail@paulgriffiths.net
*
* Basic (very) usage of astronomical library.
*
* Distributed under the terms of the GNU General Public License.
* http://www.gnu.org/licenses/
*/
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <paulgrif/utctime.h>
#include <paulgrif/astro.h>
void show_times();
int main(void) {
try {
utctime::UTCTime utc(1, 12, 31, 6, 6, 6);
} catch(utctime::UTCTimeException& e) {
std::cerr << e.what() << std::endl;
return 1;
}
utctime::UTCTime utc;
std::cout << "Current UTC time is: " << utc.time_string()
<< std::endl << std::endl;
astro::show_planet_positions(std::cout);
return 0;
}
/*
* Function shows, for a timestamp returned by a UTCTime class,
* the results of localtime(), gmtime(), and the UTC time that
* the UTCTime class thinks it generated. Used for debugging
* purposes.
*/
void show_times() {
char buffer[100];
const int year = 2013;
const int month = 4;
int day = 7;
// Set timezone (POSIX extension)
setenv("TZ", "EST-10EST-9:03:00,M10,1.0,M4.1.0/3", 1);
// Shows times for each hour in the selected day
for ( int hour = 0; hour < 24; ++hour ) {
utctime::UTCTime utc(year, month, day, hour, 0, 0);
time_t ts = utc.timestamp();
// Output local time of returned timestamp
tm* ptm = localtime(&ts);
if ( ptm == 0 ) {
std::cerr << "Couldn't get time!" << std::endl;
return;
}
tm local_tm = *ptm;
strftime(buffer, 100, "%b %d, %y %H:%M loc", &local_tm);
std::cout << buffer << " : ";
// Output GMT time of returned timestamp
ptm = gmtime(&ts);
if ( ptm == 0 ) {
std::cerr << "Couldn't get time!" << std::endl;
return;
}
tm gm_tm = *ptm;
strftime(buffer, 100, "%b %d, %y %H:%M loc", &gm_tm);
std::cout << buffer << " : ";
// Output what UTCTime class says UTC time is
std::cout << utc.time_string_inet()
<< std::endl;
}
}