Diffstat (limited to 'libopie2/opiepim/core/opimtimezone.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimtimezone.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp index be21b1b..fefceb5 100644 --- a/libopie2/opiepim/core/opimtimezone.cpp +++ b/libopie2/opiepim/core/opimtimezone.cpp | |||
@@ -8,48 +8,51 @@ | |||
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "opimtimezone.h" | 30 | #include "opimtimezone.h" |
31 | 31 | ||
32 | /* OPIE */ | ||
33 | #include <opie2/odebug.h> | ||
34 | |||
32 | /* STD */ | 35 | /* STD */ |
33 | #include <stdio.h> | 36 | #include <stdio.h> |
34 | #include <stdlib.h> | 37 | #include <stdlib.h> |
35 | #include <sys/types.h> | 38 | #include <sys/types.h> |
36 | 39 | ||
37 | namespace Opie | 40 | namespace Opie |
38 | { | 41 | { |
39 | 42 | ||
40 | QDateTime utcTime( time_t t ) | 43 | QDateTime utcTime( time_t t ) |
41 | { | 44 | { |
42 | tm * broken = ::gmtime( &t ); | 45 | tm * broken = ::gmtime( &t ); |
43 | QDateTime ret; | 46 | QDateTime ret; |
44 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); | 47 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); |
45 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | 48 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); |
46 | return ret; | 49 | return ret; |
47 | } | 50 | } |
48 | QDateTime utcTime( time_t t, const QString& zone ) | 51 | QDateTime utcTime( time_t t, const QString& zone ) |
49 | { | 52 | { |
50 | QCString org = ::getenv( "TZ" ); | 53 | QCString org = ::getenv( "TZ" ); |
51 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac | 54 | #ifndef Q_OS_MACX // Following line causes bus errors on Mac |
52 | 55 | ||
53 | ::setenv( "TZ", zone.latin1(), true ); | 56 | ::setenv( "TZ", zone.latin1(), true ); |
54 | ::tzset(); | 57 | ::tzset(); |
55 | 58 | ||
@@ -128,49 +131,49 @@ QDateTime OPimTimeZone::toUTCDateTime( const QDateTime& dt ) | |||
128 | { | 131 | { |
129 | return OPimTimeZone::utc().toDateTime( dt, *this ); | 132 | return OPimTimeZone::utc().toDateTime( dt, *this ); |
130 | } | 133 | } |
131 | 134 | ||
132 | 135 | ||
133 | QDateTime OPimTimeZone::fromUTCDateTime( time_t t ) | 136 | QDateTime OPimTimeZone::fromUTCDateTime( time_t t ) |
134 | { | 137 | { |
135 | return utcTime( t ); | 138 | return utcTime( t ); |
136 | } | 139 | } |
137 | 140 | ||
138 | 141 | ||
139 | QDateTime OPimTimeZone::toDateTime( time_t t ) | 142 | QDateTime OPimTimeZone::toDateTime( time_t t ) |
140 | { | 143 | { |
141 | return utcTime( t, m_name ); | 144 | return utcTime( t, m_name ); |
142 | } | 145 | } |
143 | 146 | ||
144 | 147 | ||
145 | /* | 148 | /* |
146 | * convert dt to utc using zone.m_name | 149 | * convert dt to utc using zone.m_name |
147 | * convert utc -> timeZoneDT using this->m_name | 150 | * convert utc -> timeZoneDT using this->m_name |
148 | */ | 151 | */ |
149 | QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone ) | 152 | QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone ) |
150 | { | 153 | { |
151 | time_t utc = to_Time_t( dt, zone.m_name ); | 154 | time_t utc = to_Time_t( dt, zone.m_name ); |
152 | qWarning( "%d %s", utc, zone.m_name.latin1() ); | 155 | owarn << "" << utc << " " << zone.m_name << "" << oendl; |
153 | return utcTime( utc, m_name ); | 156 | return utcTime( utc, m_name ); |
154 | } | 157 | } |
155 | 158 | ||
156 | 159 | ||
157 | time_t OPimTimeZone::fromDateTime( const QDateTime& time ) | 160 | time_t OPimTimeZone::fromDateTime( const QDateTime& time ) |
158 | { | 161 | { |
159 | return to_Time_t( time, m_name ); | 162 | return to_Time_t( time, m_name ); |
160 | } | 163 | } |
161 | 164 | ||
162 | 165 | ||
163 | time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) | 166 | time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) |
164 | { | 167 | { |
165 | return to_Time_t( time, "UTC" ); | 168 | return to_Time_t( time, "UTC" ); |
166 | } | 169 | } |
167 | 170 | ||
168 | 171 | ||
169 | OPimTimeZone OPimTimeZone::current() | 172 | OPimTimeZone OPimTimeZone::current() |
170 | { | 173 | { |
171 | QCString str = ::getenv( "TZ" ); | 174 | QCString str = ::getenv( "TZ" ); |
172 | OPimTimeZone zone( str ); | 175 | OPimTimeZone zone( str ); |
173 | return zone; | 176 | return zone; |
174 | } | 177 | } |
175 | 178 | ||
176 | 179 | ||