summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimtimezone.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimtimezone.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp44
1 files changed, 29 insertions, 15 deletions
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index 5b32b1f..1dc36b4 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -40,7 +40,28 @@
40namespace Opie 40namespace Opie
41{ 41{
42 42
43QDateTime utcTime( time_t t ) 43/*
44 * Save the old timeZone in a secure way (NULL Pointer check),
45 * set the new timeZone from the parameter, call tzset
46 * and then return the old timezone
47 */
48static QString setTimeZone( const QString& zone) {
49 QString old;
50 char *org = ::getenv( "TZ" );
51 if( org )
52 old = QString::fromLocal8Bit( org );
53
54 ::setenv( "TZ", zone.local8Bit(), true );
55 ::tzset();
56
57 return old;
58}
59
60static void resetTimeZone( const QString& zone ) {
61 ::setenv( "TZ", zone.local8Bit(), true );
62}
63
64static QDateTime utcTime( time_t t )
44{ 65{
45 tm * broken = ::gmtime( &t ); 66 tm * broken = ::gmtime( &t );
46 QDateTime ret; 67 QDateTime ret;
@@ -49,16 +70,13 @@ QDateTime utcTime( time_t t )
49 return ret; 70 return ret;
50} 71}
51 72
52QDateTime utcTime( time_t t, const QString& zone ) 73static QDateTime utcTime( time_t t, const QString& zone )
53{ 74{
54 QCString org = ::getenv( "TZ" );
55#ifndef Q_OS_MACX // Following line causes bus errors on Mac
56
57 ::setenv( "TZ", zone.latin1(), true );
58 ::tzset();
59 75
76#ifndef Q_OS_MACX // Following line causes bus errors on Mac
77 QString old = setTimeZone( zone );
60 tm* broken = ::localtime( &t ); 78 tm* broken = ::localtime( &t );
61 ::setenv( "TZ", org, true ); 79 resetTimeZone( old );
62#else 80#else
63#warning "Need a replacement for MacOSX!!" 81#warning "Need a replacement for MacOSX!!"
64 82
@@ -73,7 +91,7 @@ QDateTime utcTime( time_t t, const QString& zone )
73} 91}
74 92
75 93
76time_t to_Time_t( const QDateTime& utc, const QString& str ) 94static time_t to_Time_t( const QDateTime& utc, const QString& str )
77{ 95{
78 QDate d = utc.date(); 96 QDate d = utc.date();
79 QTime t = utc.time(); 97 QTime t = utc.time();
@@ -86,14 +104,10 @@ time_t to_Time_t( const QDateTime& utc, const QString& str )
86 broken.tm_min = t.minute(); 104 broken.tm_min = t.minute();
87 broken.tm_sec = t.second(); 105 broken.tm_sec = t.second();
88 106
89 QCString org = ::getenv( "TZ" );
90#ifndef Q_OS_MACX // Following line causes bus errors on Mac 107#ifndef Q_OS_MACX // Following line causes bus errors on Mac
91 108 QString old = setTimeZone( str );
92 ::setenv( "TZ", str.latin1(), true );
93 ::tzset();
94
95 time_t ti = ::mktime( &broken ); 109 time_t ti = ::mktime( &broken );
96 ::setenv( "TZ", org, true ); 110 resetTimeZone( old );
97#else 111#else
98#warning "Need a replacement for MacOSX!!" 112#warning "Need a replacement for MacOSX!!"
99 113