1 |
// Time Zones |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#include "TimeZones.hpp" |
8 |
|
9 |
int main(int argc, char* argv[]) |
10 |
{ |
11 |
TimeZones zones; |
12 |
|
13 |
return 0; |
14 |
} |
15 |
|
16 |
TimeZones::TimeZones() |
17 |
{ |
18 |
time(&now); |
19 |
display(); |
20 |
} |
21 |
|
22 |
void TimeZones::display() |
23 |
{ |
24 |
cout << "Content-Type: text/html\n\n"; |
25 |
|
26 |
struct tm* gmt = gmtime(&now); |
27 |
char date[61]; |
28 |
|
29 |
strftime(date, 61, "%A, %B %e, %Y %l:%M:%S %p %Z", gmt); |
30 |
|
31 |
cout << "<tr><td>Greenwich, England</td><td>" << date << "</td>\n"; |
32 |
|
33 |
list<pair<string, string> > zones; |
34 |
ifstream fin("timezones.dat"); |
35 |
|
36 |
while (fin.good()) |
37 |
{ |
38 |
string location, zone; |
39 |
|
40 |
getline(fin, location, '='); |
41 |
getline(fin, zone); |
42 |
|
43 |
if (zone != "") zones.push_back(pair<string, string>(location, zone)); |
44 |
} |
45 |
|
46 |
fin.close(); |
47 |
|
48 |
for (list<pair<string, string> >::iterator itor = zones.begin(); itor != |
49 |
zones.end(); itor++) |
50 |
{ |
51 |
display(itor->first, itor->second); |
52 |
} |
53 |
} |
54 |
|
55 |
void TimeZones::display(const string& location, const string& zone) |
56 |
{ |
57 |
sputenv("TZ=" + zone); |
58 |
tzset(); |
59 |
|
60 |
struct tm* when = localtime(&now); |
61 |
char date[61]; |
62 |
|
63 |
strftime(date, 61, "%A, %B %e, %Y %l:%M:%S %p %Z", when); |
64 |
|
65 |
cout << "<tr><td>" << location << "</td><td>" << date << "</td></tr>\n"; |
66 |
} |