author | mickeyl <mickeyl> | 2004-02-21 12:25:50 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-02-21 12:25:50 (UTC) |
commit | 6155f1be5c19fc51a4929c9e173f9e5a24d193e6 (patch) (unidiff) | |
tree | c18ca863f82a559c60728f922519ac696387ec53 /libopie2/opiepim/core/otimezone.cpp | |
parent | a570c2824fcecaf1c278e1b5a592fa14cc0647f8 (diff) | |
download | opie-6155f1be5c19fc51a4929c9e173f9e5a24d193e6.zip opie-6155f1be5c19fc51a4929c9e173f9e5a24d193e6.tar.gz opie-6155f1be5c19fc51a4929c9e173f9e5a24d193e6.tar.bz2 |
the usual cosmetics
Diffstat (limited to 'libopie2/opiepim/core/otimezone.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/otimezone.cpp | 88 |
1 files changed, 65 insertions, 23 deletions
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp index dab68af..e67715f 100644 --- a/libopie2/opiepim/core/otimezone.cpp +++ b/libopie2/opiepim/core/otimezone.cpp | |||
@@ -29,12 +29,14 @@ | |||
29 | 29 | ||
30 | #include "otimezone.h" | ||
31 | |||
32 | /* STD */ | ||
30 | #include <stdio.h> | 33 | #include <stdio.h> |
31 | #include <stdlib.h> | 34 | #include <stdlib.h> |
32 | |||
33 | #include <sys/types.h> | 35 | #include <sys/types.h> |
34 | 36 | ||
35 | #include <opie2/otimezone.h> | 37 | namespace Opie |
38 | { | ||
36 | 39 | ||
37 | namespace Opie { | 40 | QDateTime utcTime( time_t t ) |
38 | 41 | { | |
39 | QDateTime utcTime( time_t t) { | ||
40 | tm* broken = ::gmtime( &t ); | 42 | tm* broken = ::gmtime( &t ); |
@@ -45,5 +47,7 @@ namespace Opie { | |||
45 | } | 47 | } |
46 | QDateTime utcTime( time_t t, const QString& zone) { | 48 | QDateTime utcTime( time_t t, const QString& zone ) |
49 | { | ||
47 | QCString org = ::getenv( "TZ" ); | 50 | QCString org = ::getenv( "TZ" ); |
48 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac | 51 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac |
52 | |||
49 | ::setenv( "TZ", zone.latin1(), true ); | 53 | ::setenv( "TZ", zone.latin1(), true ); |
@@ -55,2 +59,3 @@ namespace Opie { | |||
55 | #warning "Need a replacement for MacOSX!!" | 59 | #warning "Need a replacement for MacOSX!!" |
60 | |||
56 | tm* broken = ::localtime( &t ); | 61 | tm* broken = ::localtime( &t ); |
@@ -64,3 +69,4 @@ namespace Opie { | |||
64 | } | 69 | } |
65 | time_t to_Time_t( const QDateTime& utc, const QString& str ) { | 70 | time_t to_Time_t( const QDateTime& utc, const QString& str ) |
71 | { | ||
66 | QDate d = utc.date(); | 72 | QDate d = utc.date(); |
@@ -78,2 +84,3 @@ namespace Opie { | |||
78 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac | 84 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac |
85 | |||
79 | ::setenv( "TZ", str.latin1(), true ); | 86 | ::setenv( "TZ", str.latin1(), true ); |
@@ -85,4 +92,6 @@ namespace Opie { | |||
85 | #warning "Need a replacement for MacOSX!!" | 92 | #warning "Need a replacement for MacOSX!!" |
93 | |||
86 | time_t ti = ::mktime( &broken ); | 94 | time_t ti = ::mktime( &broken ); |
87 | #endif | 95 | #endif |
96 | |||
88 | return ti; | 97 | return ti; |
@@ -91,10 +100,15 @@ namespace Opie { | |||
91 | 100 | ||
92 | namespace Opie { | 101 | namespace Opie |
102 | { | ||
93 | OTimeZone::OTimeZone( const ZoneName& zone ) | 103 | OTimeZone::OTimeZone( const ZoneName& zone ) |
94 | : m_name(zone) { | 104 | : m_name( zone ) |
95 | } | 105 | {} |
96 | OTimeZone::~OTimeZone() { | 106 | |
97 | } | 107 | |
108 | OTimeZone::~OTimeZone() | ||
109 | {} | ||
98 | 110 | ||
99 | bool OTimeZone::isValid()const { | 111 | |
112 | bool OTimeZone::isValid() const | ||
113 | { | ||
100 | return !m_name.isEmpty(); | 114 | return !m_name.isEmpty(); |
@@ -106,14 +120,26 @@ bool OTimeZone::isValid()const { | |||
106 | */ | 120 | */ |
107 | QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { | 121 | QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt ) |
122 | { | ||
108 | return OTimeZone::current().toDateTime( dt, *this ); | 123 | return OTimeZone::current().toDateTime( dt, *this ); |
109 | } | 124 | } |
110 | QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { | 125 | |
126 | |||
127 | QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) | ||
128 | { | ||
111 | return OTimeZone::utc().toDateTime( dt, *this ); | 129 | return OTimeZone::utc().toDateTime( dt, *this ); |
112 | } | 130 | } |
113 | QDateTime OTimeZone::fromUTCDateTime( time_t t) { | 131 | |
132 | |||
133 | QDateTime OTimeZone::fromUTCDateTime( time_t t ) | ||
134 | { | ||
114 | return utcTime( t ); | 135 | return utcTime( t ); |
115 | } | 136 | } |
116 | QDateTime OTimeZone::toDateTime( time_t t) { | 137 | |
138 | |||
139 | QDateTime OTimeZone::toDateTime( time_t t ) | ||
140 | { | ||
117 | return utcTime( t, m_name ); | 141 | return utcTime( t, m_name ); |
118 | } | 142 | } |
143 | |||
144 | |||
119 | /* | 145 | /* |
@@ -122,3 +148,4 @@ QDateTime OTimeZone::toDateTime( time_t t) { | |||
122 | */ | 148 | */ |
123 | QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { | 149 | QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) |
150 | { | ||
124 | time_t utc = to_Time_t( dt, zone.m_name ); | 151 | time_t utc = to_Time_t( dt, zone.m_name ); |
@@ -127,9 +154,18 @@ QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { | |||
127 | } | 154 | } |
128 | time_t OTimeZone::fromDateTime( const QDateTime& time ) { | 155 | |
156 | |||
157 | time_t OTimeZone::fromDateTime( const QDateTime& time ) | ||
158 | { | ||
129 | return to_Time_t( time, m_name ); | 159 | return to_Time_t( time, m_name ); |
130 | } | 160 | } |
131 | time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { | 161 | |
162 | |||
163 | time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) | ||
164 | { | ||
132 | return to_Time_t( time, "UTC" ); | 165 | return to_Time_t( time, "UTC" ); |
133 | } | 166 | } |
134 | OTimeZone OTimeZone::current() { | 167 | |
168 | |||
169 | OTimeZone OTimeZone::current() | ||
170 | { | ||
135 | QCString str = ::getenv("TZ"); | 171 | QCString str = ::getenv("TZ"); |
@@ -138,6 +174,12 @@ OTimeZone OTimeZone::current() { | |||
138 | } | 174 | } |
139 | OTimeZone OTimeZone::utc() { | 175 | |
176 | |||
177 | OTimeZone OTimeZone::utc() | ||
178 | { | ||
140 | return OTimeZone("UTC"); | 179 | return OTimeZone("UTC"); |
141 | } | 180 | } |
142 | QString OTimeZone::timeZone()const { | 181 | |
182 | |||
183 | QString OTimeZone::timeZone() const | ||
184 | { | ||
143 | return m_name; | 185 | return m_name; |