author | zecke <zecke> | 2004-11-18 21:45:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-11-18 21:45:49 (UTC) |
commit | 7484344ff5be1f7c54e51715776d0e3cadeb1ed0 (patch) (unidiff) | |
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) (show 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 | |||
@@ -19,102 +19,116 @@ | |||
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 */ | 32 | /* OPIE */ |
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
34 | 34 | ||
35 | /* STD */ | 35 | /* STD */ |
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
39 | 39 | ||
40 | namespace Opie | 40 | namespace Opie |
41 | { | 41 | { |
42 | 42 | ||
43 | QDateTime 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 | */ | ||
48 | static 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 | |||
60 | static void resetTimeZone( const QString& zone ) { | ||
61 | ::setenv( "TZ", zone.local8Bit(), true ); | ||
62 | } | ||
63 | |||
64 | static QDateTime utcTime( time_t t ) | ||
44 | { | 65 | { |
45 | tm * broken = ::gmtime( &t ); | 66 | tm * broken = ::gmtime( &t ); |
46 | QDateTime ret; | 67 | QDateTime ret; |
47 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); | 68 | 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 ) ); | 69 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); |
49 | return ret; | 70 | return ret; |
50 | } | 71 | } |
51 | 72 | ||
52 | QDateTime utcTime( time_t t, const QString& zone ) | 73 | static 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 | ||
65 | tm* broken = ::localtime( &t ); | 83 | tm* broken = ::localtime( &t ); |
66 | #endif | 84 | #endif |
67 | 85 | ||
68 | QDateTime ret; | 86 | QDateTime ret; |
69 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); | 87 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday ) ); |
70 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | 88 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); |
71 | 89 | ||
72 | return ret; | 90 | return ret; |
73 | } | 91 | } |
74 | 92 | ||
75 | 93 | ||
76 | time_t to_Time_t( const QDateTime& utc, const QString& str ) | 94 | static 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(); |
80 | 98 | ||
81 | tm broken; | 99 | tm broken; |
82 | broken.tm_year = d.year() - 1900; | 100 | broken.tm_year = d.year() - 1900; |
83 | broken.tm_mon = d.month() - 1; | 101 | broken.tm_mon = d.month() - 1; |
84 | broken.tm_mday = d.day(); | 102 | broken.tm_mday = d.day(); |
85 | broken.tm_hour = t.hour(); | 103 | broken.tm_hour = t.hour(); |
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 | ||
100 | time_t ti = ::mktime( &broken ); | 114 | time_t ti = ::mktime( &broken ); |
101 | #endif | 115 | #endif |
102 | 116 | ||
103 | return ti; | 117 | return ti; |
104 | } | 118 | } |
105 | } | 119 | } |
106 | 120 | ||
107 | namespace Opie | 121 | namespace Opie |
108 | { | 122 | { |
109 | OPimTimeZone::OPimTimeZone( const ZoneName& zone ) | 123 | OPimTimeZone::OPimTimeZone( const ZoneName& zone ) |
110 | : m_name( zone ) | 124 | : m_name( zone ) |
111 | {} | 125 | {} |
112 | 126 | ||
113 | 127 | ||
114 | OPimTimeZone::~OPimTimeZone() | 128 | OPimTimeZone::~OPimTimeZone() |
115 | {} | 129 | {} |
116 | 130 | ||
117 | 131 | ||
118 | bool OPimTimeZone::isValid() const | 132 | bool OPimTimeZone::isValid() const |
119 | { | 133 | { |
120 | return !m_name.isEmpty(); | 134 | return !m_name.isEmpty(); |