summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/otimezone.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/otimezone.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/otimezone.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp
index 34659c3..dab68af 100644
--- a/libopie2/opiepim/core/otimezone.cpp
+++ b/libopie2/opiepim/core/otimezone.cpp
@@ -1,20 +1,49 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
1#include <stdio.h> 30#include <stdio.h>
2#include <stdlib.h> 31#include <stdlib.h>
3 32
4#include <sys/types.h> 33#include <sys/types.h>
5 34
6#include "otimezone.h" 35#include <opie2/otimezone.h>
7 36
8namespace { 37namespace Opie {
9 38
10 QDateTime utcTime( time_t t) { 39 QDateTime utcTime( time_t t) {
11 tm* broken = ::gmtime( &t ); 40 tm* broken = ::gmtime( &t );
12 QDateTime ret; 41 QDateTime ret;
13 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) ); 42 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 ) ); 43 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
15 return ret; 44 return ret;
16 } 45 }
17 QDateTime utcTime( time_t t, const QString& zone) { 46 QDateTime utcTime( time_t t, const QString& zone) {
18 QCString org = ::getenv( "TZ" ); 47 QCString org = ::getenv( "TZ" );
19#ifndef Q_OS_MACX // Following line causes bus errors on Mac 48#ifndef Q_OS_MACX // Following line causes bus errors on Mac
20 ::setenv( "TZ", zone.latin1(), true ); 49 ::setenv( "TZ", zone.latin1(), true );
@@ -50,24 +79,26 @@ namespace {
50 ::setenv( "TZ", str.latin1(), true ); 79 ::setenv( "TZ", str.latin1(), true );
51 ::tzset(); 80 ::tzset();
52 81
53 time_t ti = ::mktime( &broken ); 82 time_t ti = ::mktime( &broken );
54 ::setenv( "TZ", org, true ); 83 ::setenv( "TZ", org, true );
55#else 84#else
56#warning "Need a replacement for MacOSX!!" 85#warning "Need a replacement for MacOSX!!"
57 time_t ti = ::mktime( &broken ); 86 time_t ti = ::mktime( &broken );
58#endif 87#endif
59 return ti; 88 return ti;
60 } 89 }
61} 90}
91
92namespace Opie {
62OTimeZone::OTimeZone( const ZoneName& zone ) 93OTimeZone::OTimeZone( const ZoneName& zone )
63 : m_name(zone) { 94 : m_name(zone) {
64} 95}
65OTimeZone::~OTimeZone() { 96OTimeZone::~OTimeZone() {
66} 97}
67 98
68bool OTimeZone::isValid()const { 99bool OTimeZone::isValid()const {
69 return !m_name.isEmpty(); 100 return !m_name.isEmpty();
70} 101}
71 102
72/* 103/*
73 * we will get the current timezone 104 * we will get the current timezone
@@ -102,12 +133,14 @@ time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) {
102} 133}
103OTimeZone OTimeZone::current() { 134OTimeZone OTimeZone::current() {
104 QCString str = ::getenv("TZ"); 135 QCString str = ::getenv("TZ");
105 OTimeZone zone( str ); 136 OTimeZone zone( str );
106 return zone; 137 return zone;
107} 138}
108OTimeZone OTimeZone::utc() { 139OTimeZone OTimeZone::utc() {
109 return OTimeZone("UTC"); 140 return OTimeZone("UTC");
110} 141}
111QString OTimeZone::timeZone()const { 142QString OTimeZone::timeZone()const {
112 return m_name; 143 return m_name;
113} 144}
145
146}