author | zecke <zecke> | 2004-11-18 21:45:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-11-18 21:45:49 (UTC) |
commit | 7484344ff5be1f7c54e51715776d0e3cadeb1ed0 (patch) (side-by-side diff) | |
tree | 96f427f7a1fb1c8ca0a6efbd72b51e916cb1651d /libopie2/opiepim/core/opimtimezone.cpp | |
parent | 3302eb30390e6053637929316670da3e8fbe279e (diff) | |
download | opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.zip opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.gz opie-7484344ff5be1f7c54e51715776d0e3cadeb1ed0.tar.bz2 |
Big PIM API Update Core Part (1/2 of what should be implemented):
OPimRecords:
-Add a so called safeCast using the rtti value
OPimTodo:
-Fix memleak with OPimState
OPimOccurrence:
-New class. Every 'Access' can give occurrences
for a period of time
Move Documentation
Diffstat (limited to 'libopie2/opiepim/core/opimtimezone.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimtimezone.cpp | 44 |
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 @@ -39,27 +39,45 @@ namespace Opie { -QDateTime utcTime( time_t t ) +/* + * Save the old timeZone in a secure way (NULL Pointer check), + * set the new timeZone from the parameter, call tzset + * and then return the old timezone + */ +static QString setTimeZone( const QString& zone) { + QString old; + char *org = ::getenv( "TZ" ); + if( org ) + old = QString::fromLocal8Bit( org ); + + ::setenv( "TZ", zone.local8Bit(), true ); + ::tzset(); + + return old; +} + +static void resetTimeZone( const QString& zone ) { + ::setenv( "TZ", zone.local8Bit(), true ); +} + +static QDateTime utcTime( time_t t ) { tm * broken = ::gmtime( &t ); QDateTime ret; ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); return ret; } -QDateTime utcTime( time_t t, const QString& zone ) +static QDateTime utcTime( time_t t, const QString& zone ) { - QCString org = ::getenv( "TZ" ); -#ifndef Q_OS_MACX // Following line causes bus errors on Mac - - ::setenv( "TZ", zone.latin1(), true ); - ::tzset(); +#ifndef Q_OS_MACX // Following line causes bus errors on Mac + QString old = setTimeZone( zone ); tm* broken = ::localtime( &t ); - ::setenv( "TZ", org, true ); + resetTimeZone( old ); #else #warning "Need a replacement for MacOSX!!" tm* broken = ::localtime( &t ); @@ -72,9 +90,9 @@ QDateTime utcTime( time_t t, const QString& zone ) return ret; } -time_t to_Time_t( const QDateTime& utc, const QString& str ) +static time_t to_Time_t( const QDateTime& utc, const QString& str ) { QDate d = utc.date(); QTime t = utc.time(); @@ -85,16 +103,12 @@ time_t to_Time_t( const QDateTime& utc, const QString& str ) broken.tm_hour = t.hour(); broken.tm_min = t.minute(); broken.tm_sec = t.second(); - QCString org = ::getenv( "TZ" ); #ifndef Q_OS_MACX // Following line causes bus errors on Mac - - ::setenv( "TZ", str.latin1(), true ); - ::tzset(); - + QString old = setTimeZone( str ); time_t ti = ::mktime( &broken ); - ::setenv( "TZ", org, true ); + resetTimeZone( old ); #else #warning "Need a replacement for MacOSX!!" time_t ti = ::mktime( &broken ); |