1 |
Douglas Thrift |
53 |
// Time Zones |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
|
|
#ifndef _TimeZones_hpp_ |
8 |
|
|
#define _TimeZones_hpp_ |
9 |
|
|
|
10 |
|
|
#include <iostream> |
11 |
|
|
#include <string> |
12 |
|
|
#include <cstdlib> |
13 |
|
|
#include <cstdio> |
14 |
|
|
#include <ctime> |
15 |
|
|
|
16 |
|
|
using namespace std; |
17 |
|
|
|
18 |
|
|
inline string sgetenv(const string& name) |
19 |
|
|
{ |
20 |
|
|
char* value = getenv(name.c_str()); |
21 |
|
|
|
22 |
|
|
return value != NULL ? value : ""; |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
inline int sputenv(const string& name) |
26 |
|
|
{ |
27 |
|
|
char* value = new char[name.size() + 1]; |
28 |
|
|
|
29 |
|
|
sprintf(value, name.c_str()); |
30 |
|
|
|
31 |
|
|
int code = putenv(value); |
32 |
|
|
|
33 |
|
|
delete [] value; |
34 |
|
|
|
35 |
|
|
return code; |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
inline void sunsetenv(const string& name) { unsetenv(name.c_str()); } |
39 |
|
|
|
40 |
|
|
#ifdef __CYGWIN__ |
41 |
|
|
|
42 |
|
|
inline time_t timegm(struct tm* time) |
43 |
|
|
{ |
44 |
|
|
string zone = sgetenv("TZ"); |
45 |
|
|
|
46 |
|
|
sputenv("TZ="); |
47 |
|
|
tzset(); |
48 |
|
|
|
49 |
|
|
time_t when = mktime(time); |
50 |
|
|
|
51 |
|
|
sputenv("TZ=" + zone); |
52 |
|
|
tzset(); |
53 |
|
|
|
54 |
|
|
return when; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
#endif |
58 |
|
|
|
59 |
|
|
class TimeZones |
60 |
|
|
{ |
61 |
|
|
private: |
62 |
|
|
// |
63 |
|
|
public: |
64 |
|
|
TimeZones(); |
65 |
|
|
~TimeZones() {} |
66 |
|
|
}; |
67 |
|
|
|
68 |
|
|
#endif // _TimeZones_hpp_ |