ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/TimeZones/TimeZones.cpp
Revision: 55
Committed: 2003-12-14T15:24:18-08:00 (21 years, 6 months ago) by Douglas Thrift
File size: 1174 byte(s)
Log Message:
The universe explodes! What time is it really?
Yes.

File Contents

# User Rev Content
1 Douglas Thrift 53 // 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 Douglas Thrift 55 time(&now);
19     display();
20 Douglas Thrift 53 }
21 Douglas Thrift 55
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,&nbsp;%Y %l:%M:%S&nbsp;%p&nbsp;%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,&nbsp;%Y %l:%M:%S&nbsp;%p&nbsp;%Z", when);
64    
65     cout << "<tr><td>" << location << "</td><td>" << date << "</td></tr>\n";
66     }

Properties

Name Value
svn:eol-style native
svn:keywords Id