summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimtimezone.cpp
authorzecke <zecke>2004-07-29 19:42:59 (UTC)
committer zecke <zecke>2004-07-29 19:42:59 (UTC)
commit52b1ae9281920cf5a40fe543112d8b00e7699ef6 (patch) (unidiff)
tree0b0a79ff9a45a66f32fe555ee662b4acc8f6eff9 /libopie2/opiepim/core/opimtimezone.cpp
parentc170d1f931ae03c2ec917b7abf4bd5d0e94a3760 (diff)
downloadopie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.zip
opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.tar.gz
opie-52b1ae9281920cf5a40fe543112d8b00e7699ef6.tar.bz2
-UTC -> Europe/London when referring to no timezone
-special handling for allDay Event in OPImEvent, avoid setting timezone as it is by default UTC -No timezone set by default for an Event -Recurrence is UTC (no timezone) -Provide upgrade path from DateBook as by default events were in the current timezone but didn't have the timezone attribute -unified handling of timezones, compatible with QtopiaDesktop -do less conversions -...
Diffstat (limited to 'libopie2/opiepim/core/opimtimezone.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index fefceb5..5b32b1f 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -39,46 +39,49 @@
39 39
40namespace Opie 40namespace Opie
41{ 41{
42 42
43QDateTime utcTime( time_t t ) 43QDateTime utcTime( time_t t )
44{ 44{
45 tm * broken = ::gmtime( &t ); 45 tm * broken = ::gmtime( &t );
46 QDateTime ret; 46 QDateTime ret;
47 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 ) );
48 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 ) );
49 return ret; 49 return ret;
50} 50}
51
51QDateTime utcTime( time_t t, const QString& zone ) 52QDateTime utcTime( time_t t, const QString& zone )
52{ 53{
53 QCString org = ::getenv( "TZ" ); 54 QCString org = ::getenv( "TZ" );
54#ifndef Q_OS_MACX // Following line causes bus errors on Mac 55#ifndef Q_OS_MACX // Following line causes bus errors on Mac
55 56
56 ::setenv( "TZ", zone.latin1(), true ); 57 ::setenv( "TZ", zone.latin1(), true );
57 ::tzset(); 58 ::tzset();
58 59
59 tm* broken = ::localtime( &t ); 60 tm* broken = ::localtime( &t );
60 ::setenv( "TZ", org, true ); 61 ::setenv( "TZ", org, true );
61#else 62#else
62#warning "Need a replacement for MacOSX!!" 63#warning "Need a replacement for MacOSX!!"
63 64
64 tm* broken = ::localtime( &t ); 65 tm* broken = ::localtime( &t );
65#endif 66#endif
66 67
67 QDateTime ret; 68 QDateTime ret;
68 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); 69 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) );
69 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); 70 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
70 71
71 return ret; 72 return ret;
72} 73}
74
75
73time_t to_Time_t( const QDateTime& utc, const QString& str ) 76time_t to_Time_t( const QDateTime& utc, const QString& str )
74{ 77{
75 QDate d = utc.date(); 78 QDate d = utc.date();
76 QTime t = utc.time(); 79 QTime t = utc.time();
77 80
78 tm broken; 81 tm broken;
79 broken.tm_year = d.year() - 1900; 82 broken.tm_year = d.year() - 1900;
80 broken.tm_mon = d.month() - 1; 83 broken.tm_mon = d.month() - 1;
81 broken.tm_mday = d.day(); 84 broken.tm_mday = d.day();
82 broken.tm_hour = t.hour(); 85 broken.tm_hour = t.hour();
83 broken.tm_min = t.minute(); 86 broken.tm_min = t.minute();
84 broken.tm_sec = t.second(); 87 broken.tm_sec = t.second();
@@ -142,50 +145,49 @@ QDateTime OPimTimeZone::fromUTCDateTime( time_t t )
142QDateTime OPimTimeZone::toDateTime( time_t t ) 145QDateTime OPimTimeZone::toDateTime( time_t t )
143{ 146{
144 return utcTime( t, m_name ); 147 return utcTime( t, m_name );
145} 148}
146 149
147 150
148/* 151/*
149 * convert dt to utc using zone.m_name 152 * convert dt to utc using zone.m_name
150 * convert utc -> timeZoneDT using this->m_name 153 * convert utc -> timeZoneDT using this->m_name
151 */ 154 */
152QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone ) 155QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone )
153{ 156{
154 time_t utc = to_Time_t( dt, zone.m_name ); 157 time_t utc = to_Time_t( dt, m_name );
155 owarn << "" << utc << " " << zone.m_name << "" << oendl; 158 return utcTime( utc, zone.m_name );
156 return utcTime( utc, m_name );
157} 159}
158 160
159 161
160time_t OPimTimeZone::fromDateTime( const QDateTime& time ) 162time_t OPimTimeZone::fromDateTime( const QDateTime& time )
161{ 163{
162 return to_Time_t( time, m_name ); 164 return to_Time_t( time, m_name );
163} 165}
164 166
165 167
166time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time ) 168time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time )
167{ 169{
168 return to_Time_t( time, "UTC" ); 170 return to_Time_t( time, "Europe/London" );
169} 171}
170 172
171 173
172OPimTimeZone OPimTimeZone::current() 174OPimTimeZone OPimTimeZone::current()
173{ 175{
174 QCString str = ::getenv( "TZ" ); 176 QCString str = ::getenv( "TZ" );
175 OPimTimeZone zone( str ); 177 OPimTimeZone zone( str );
176 return zone; 178 return zone;
177} 179}
178 180
179 181
180OPimTimeZone OPimTimeZone::utc() 182OPimTimeZone OPimTimeZone::utc()
181{ 183{
182 return OPimTimeZone( "UTC" ); 184 return OPimTimeZone( "Europe/London" );
183} 185}
184 186
185 187
186QString OPimTimeZone::timeZone() const 188QString OPimTimeZone::timeZone() const
187{ 189{
188 return m_name; 190 return m_name;
189} 191}
190 192
191} 193}