author | zecke <zecke> | 2003-02-21 16:52:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-21 16:52:49 (UTC) |
commit | 0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7 (patch) (unidiff) | |
tree | f3ce9c9441a1073762f3e0c61cc85f0d5a1fd81d /libopie2/opiepim/core/otimezone.cpp | |
parent | a298235aa1489937e7657079e6352adfc8746acf (diff) | |
download | opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.zip opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.tar.gz opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.tar.bz2 |
-Remove old Todo classes they're deprecated and today I already using the
new API
-Guard against self assignment in OTodo
-Add test apps for OPIM
-Opiefied Event classes
-Added TimeZone handling and pinning of TimeZones to OEvent
-Adjust ORecur and the widget to better timezone behaviour
Diffstat (limited to 'libopie2/opiepim/core/otimezone.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/otimezone.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp new file mode 100644 index 0000000..b2bd3aa --- a/dev/null +++ b/libopie2/opiepim/core/otimezone.cpp | |||
@@ -0,0 +1,104 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | |||
6 | #include "otimezone.h" | ||
7 | |||
8 | namespace { | ||
9 | |||
10 | QDateTime utcTime( time_t t) { | ||
11 | tm* broken = ::gmtime( &t ); | ||
12 | QDateTime ret; | ||
13 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); | ||
14 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | ||
15 | return ret; | ||
16 | } | ||
17 | QDateTime utcTime( time_t t, const QString& zone) { | ||
18 | QCString org = ::getenv( "TZ" ); | ||
19 | ::setenv( "TZ", zone.latin1(), true ); | ||
20 | ::tzset(); | ||
21 | |||
22 | tm* broken = ::localtime( &t ); | ||
23 | ::setenv( "TZ", org, true ); | ||
24 | |||
25 | QDateTime ret; | ||
26 | ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); | ||
27 | ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) ); | ||
28 | |||
29 | return ret; | ||
30 | } | ||
31 | time_t to_Time_t( const QDateTime& utc, const QString& str ) { | ||
32 | QDate d = utc.date(); | ||
33 | QTime t = utc.time(); | ||
34 | |||
35 | tm broken; | ||
36 | broken.tm_year = d.year() - 1900; | ||
37 | broken.tm_mon = d.month() - 1; | ||
38 | broken.tm_mday = d.day(); | ||
39 | broken.tm_hour = t.hour(); | ||
40 | broken.tm_min = t.minute(); | ||
41 | broken.tm_sec = t.second(); | ||
42 | |||
43 | QCString org = ::getenv( "TZ" ); | ||
44 | ::setenv( "TZ", str.latin1(), true ); | ||
45 | ::tzset(); | ||
46 | |||
47 | time_t ti = ::mktime( &broken ); | ||
48 | ::setenv( "TZ", org, true ); | ||
49 | |||
50 | return ti; | ||
51 | } | ||
52 | } | ||
53 | OTimeZone::OTimeZone( const ZoneName& zone ) | ||
54 | : m_name(zone) { | ||
55 | } | ||
56 | OTimeZone::~OTimeZone() { | ||
57 | } | ||
58 | |||
59 | bool OTimeZone::isValid()const { | ||
60 | return !m_name.isEmpty(); | ||
61 | } | ||
62 | |||
63 | /* | ||
64 | * we will get the current timezone | ||
65 | * and ask it to convert to the timezone date | ||
66 | */ | ||
67 | QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { | ||
68 | return OTimeZone::current().toDateTime( dt, *this ); | ||
69 | } | ||
70 | QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { | ||
71 | return OTimeZone::utc().toDateTime( dt, *this ); | ||
72 | } | ||
73 | QDateTime OTimeZone::fromUTCDateTime( time_t t) { | ||
74 | return utcTime( t ); | ||
75 | } | ||
76 | QDateTime OTimeZone::toDateTime( time_t t) { | ||
77 | return utcTime( t, m_name ); | ||
78 | } | ||
79 | /* | ||
80 | * convert dt to utc using zone.m_name | ||
81 | * convert utc -> timeZoneDT using this->m_name | ||
82 | */ | ||
83 | QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) { | ||
84 | time_t utc = to_Time_t( dt, zone.m_name ); | ||
85 | qWarning("%d %s", utc, zone.m_name.latin1() ); | ||
86 | return utcTime( utc, m_name ); | ||
87 | } | ||
88 | time_t OTimeZone::fromDateTime( const QDateTime& time ) { | ||
89 | return to_Time_t( time, m_name ); | ||
90 | } | ||
91 | time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { | ||
92 | return to_Time_t( time, "UTC" ); | ||
93 | } | ||
94 | OTimeZone OTimeZone::current() { | ||
95 | QCString str = ::getenv("TZ"); | ||
96 | OTimeZone zone( str ); | ||
97 | return zone; | ||
98 | } | ||
99 | OTimeZone OTimeZone::utc() { | ||
100 | return OTimeZone("UTC"); | ||
101 | } | ||
102 | QString OTimeZone::timeZone()const { | ||
103 | return m_name; | ||
104 | } | ||