-rw-r--r-- | libopie/pim/otimezone.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libopie/pim/otimezone.h b/libopie/pim/otimezone.h new file mode 100644 index 0000000..bb08349 --- a/dev/null +++ b/libopie/pim/otimezone.h | |||
@@ -0,0 +1,71 @@ | |||
1 | #ifndef OPIE_TIME_ZONE_H | ||
2 | #define OPIE_TIME_ZONE_H | ||
3 | |||
4 | #include <time.h> | ||
5 | #include <qdatetime.h> | ||
6 | |||
7 | /** | ||
8 | * A very primitive class to convert time | ||
9 | * from one timezone to another | ||
10 | * and to localtime | ||
11 | * and time_t | ||
12 | */ | ||
13 | class OTimeZone { | ||
14 | public: | ||
15 | typedef QString ZoneName; | ||
16 | OTimeZone( const ZoneName& = ZoneName::null ); | ||
17 | virtual ~OTimeZone(); // just in case. | ||
18 | |||
19 | bool isValid()const; | ||
20 | |||
21 | /** | ||
22 | * converts the QDateTime to a DateTime | ||
23 | * in the local timezone | ||
24 | * if QDateTime is 25th Jan and takes place in Europe/Berlin at 12h | ||
25 | * and the current timezone is Europe/London the returned | ||
26 | * time will be 11h. | ||
27 | */ | ||
28 | QDateTime toLocalDateTime( const QDateTime& dt ); | ||
29 | |||
30 | /** | ||
31 | * converts the QDateTime to UTC time | ||
32 | */ | ||
33 | QDateTime toUTCDateTime( const QDateTime& dt ); | ||
34 | |||
35 | /** | ||
36 | * reads the time_t into a QDateTime using UTC as timezone! | ||
37 | */ | ||
38 | QDateTime fromUTCDateTime( time_t ); | ||
39 | |||
40 | /** | ||
41 | * converts the time_t to the time in the timezone | ||
42 | */ | ||
43 | QDateTime toDateTime( time_t ); | ||
44 | |||
45 | /** | ||
46 | * converts the QDateTime from one timezone to this timeZone | ||
47 | */ | ||
48 | QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone ); | ||
49 | |||
50 | /** | ||
51 | * converts the date time into a time_t. It takes the timezone into account | ||
52 | */ | ||
53 | time_t fromDateTime( const QDateTime& ); | ||
54 | |||
55 | /** | ||
56 | * converts the datetime with timezone UTC | ||
57 | */ | ||
58 | time_t fromUTCDateTime( const QDateTime& ); | ||
59 | |||
60 | static OTimeZone current(); | ||
61 | static OTimeZone utc(); | ||
62 | |||
63 | QString timeZone()const; | ||
64 | private: | ||
65 | ZoneName m_name; | ||
66 | class Private; | ||
67 | Private* d; | ||
68 | }; | ||
69 | |||
70 | |||
71 | #endif | ||