summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/core') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimevent.cpp36
-rw-r--r--libopie2/opiepim/core/opimrecurrence.cpp10
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp12
3 files changed, 28 insertions, 30 deletions
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 8752fce..739cb6f 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -293,14 +293,16 @@ void OPimEvent::setStartDateTime( const QDateTime& dt )
QDateTime OPimEvent::endDateTime() const
{
/*
* if all Day event the end time needs
* to be on the same day as the start
*/
- if ( data->isAllDay )
- return QDateTime( data->start.date(), QTime( 23, 59, 59 ) );
+ if ( data->isAllDay ) {
+ QDate end = data->end.isValid() ? data->end.date() : data->start.date() ;
+ return QDateTime( end, QTime( 23, 59, 59 ) );
+ }
return data->end;
}
QDateTime OPimEvent::endDateTimeInZone() const
{
@@ -332,26 +334,25 @@ bool OPimEvent::isAllDay() const
void OPimEvent::setAllDay( bool allDay )
{
changeOrModify();
data->isAllDay = allDay;
- if ( allDay ) data->timezone = "UTC";
}
void OPimEvent::setTimeZone( const QString& tz )
{
changeOrModify();
data->timezone = tz;
}
QString OPimEvent::timeZone() const
{
- if ( data->isAllDay ) return QString::fromLatin1( "UTC" );
+ if ( data->isAllDay ) return QString::fromLatin1( "Europe/London" );
return data->timezone;
}
bool OPimEvent::match( const QRegExp& re ) const
{
@@ -561,15 +562,16 @@ QMap<int, QString> OPimEvent::toMap() const
// Currently we just support one alarm.. (eilers)
OPimAlarm alarm = notifiers().alarms() [ 0 ];
retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
}
- OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
- retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) );
- retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) );
+ /* either use UTC timeZone or current() if there is was a timezone set */
+ OPimTimeZone zone( (timeZone().isEmpty()||isAllDay()) ? OPimTimeZone::utc() : OPimTimeZone::current() );
+ retMap.insert( OPimEvent::FStart, QString::number( zone.fromDateTime( startDateTime())));
+ retMap.insert( OPimEvent::FEnd, QString::number( zone.fromDateTime( endDateTime() )));
retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
if ( parent() )
retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
if ( children().count() )
{
@@ -633,27 +635,21 @@ void OPimEvent::fromMap( const QMap<int, QString>& map )
time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
/* AllDay is always in UTC */
if ( isAllDay() )
{
OPimTimeZone utc = OPimTimeZone::utc();
- setStartDateTime( utc.fromUTCDateTime( start ) );
- setEndDateTime ( utc.fromUTCDateTime( end ) );
- setTimeZone( "UTC" ); // make sure it is really utc
+ setStartDateTime(utc.toDateTime( start ) );
+ setEndDateTime ( utc.toDateTime( end ) );
}
- else
- {
+ else {
/* to current date time */
- // owarn << " Start is " << start << "" << oendl;
- OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
- QDateTime date = zone.toDateTime( start );
- owarn << " Start is " << date.toString() << "" << oendl;
- setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
-
- date = zone.toDateTime( end );
- setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
+ OPimTimeZone to_zone( ev.timeZone().isEmpty() ? OPimTimeZone::utc() : OPimTimeZone::current() );
+
+ ev.setStartDateTime(to_zone.toDateTime( start));
+ ev.setEndDateTime (to_zone.toDateTime( end));
}
int alarmTime = -1;
if ( !map[ OPimEvent::FAlarm ].isEmpty() )
alarmTime = map[ OPimEvent::FAlarm ].toInt();
diff --git a/libopie2/opiepim/core/opimrecurrence.cpp b/libopie2/opiepim/core/opimrecurrence.cpp
index 4b1d886..c3ae350 100644
--- a/libopie2/opiepim/core/opimrecurrence.cpp
+++ b/libopie2/opiepim/core/opimrecurrence.cpp
@@ -636,14 +636,14 @@ QMap<int, QString> OPimRecurrence::toMap() const
retMap.insert( OPimRecurrence::RType, rTypeString() );
retMap.insert( OPimRecurrence::RWeekdays, QString::number( static_cast<int>( data->days ) ) );
retMap.insert( OPimRecurrence::RPosition, QString::number(data->pos ) );
retMap.insert( OPimRecurrence::RFreq, QString::number( data->freq ) );
retMap.insert( OPimRecurrence::RHasEndDate, QString::number( static_cast<int>( data->hasEnd ) ) );
if( data -> hasEnd )
- retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::utc().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) );
- retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::utc().fromUTCDateTime( data->create ) ) );
+ retMap.insert( OPimRecurrence::EndDate, QString::number( OPimTimeZone::current().fromUTCDateTime( QDateTime( data->end, QTime(12,0,0) ) ) ) );
+ retMap.insert( OPimRecurrence::Created, QString::number( OPimTimeZone::current().fromUTCDateTime( data->create ) ) );
if ( data->list.isEmpty() ) return retMap;
// save exceptions list here!!
ExceptionList::ConstIterator it;
ExceptionList list = data->list;
@@ -667,17 +667,17 @@ void OPimRecurrence::fromMap( const QMap<int, QString>& map )
data -> type = repTypeMap[ map [OPimRecurrence::RType] ];
data -> days = (char) map[ OPimRecurrence::RWeekdays ].toInt();
data -> pos = map[ OPimRecurrence::RPosition ].toInt();
data -> freq = map[ OPimRecurrence::RFreq ].toInt();
data -> hasEnd= map[ OPimRecurrence::RHasEndDate ].toInt() ? true : false;
- OPimTimeZone utc = OPimTimeZone::utc();
+ OPimTimeZone cur = OPimTimeZone::current();
if ( data -> hasEnd ){
- data -> end = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date();
+ data -> end = cur.fromUTCDateTime( (time_t) map[ OPimRecurrence::EndDate ].toLong() ).date();
}
- data -> create = utc.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date();
+ data -> create = cur.fromUTCDateTime( (time_t) map[ OPimRecurrence::Created ].toLong() ).date();
#if 0
// FIXME: Exceptions currently not supported...
// Convert the list of exceptions from QString into ExceptionList
data -> list.clear();
QString exceptStr = map[ OPimRecurrence::Exceptions ];
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index fefceb5..5b32b1f 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -45,12 +45,13 @@ 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 )
{
QCString org = ::getenv( "TZ" );
#ifndef Q_OS_MACX // Following line causes bus errors on Mac
::setenv( "TZ", zone.latin1(), true );
@@ -67,12 +68,14 @@ QDateTime utcTime( time_t t, const QString& zone )
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;
}
+
+
time_t to_Time_t( const QDateTime& utc, const QString& str )
{
QDate d = utc.date();
QTime t = utc.time();
tm broken;
@@ -148,27 +151,26 @@ QDateTime OPimTimeZone::toDateTime( time_t t )
/*
* convert dt to utc using zone.m_name
* convert utc -> timeZoneDT using this->m_name
*/
QDateTime OPimTimeZone::toDateTime( const QDateTime& dt, const OPimTimeZone& zone )
{
- time_t utc = to_Time_t( dt, zone.m_name );
- owarn << "" << utc << " " << zone.m_name << "" << oendl;
- return utcTime( utc, m_name );
+ time_t utc = to_Time_t( dt, m_name );
+ return utcTime( utc, zone.m_name );
}
time_t OPimTimeZone::fromDateTime( const QDateTime& time )
{
return to_Time_t( time, m_name );
}
time_t OPimTimeZone::fromUTCDateTime( const QDateTime& time )
{
- return to_Time_t( time, "UTC" );
+ return to_Time_t( time, "Europe/London" );
}
OPimTimeZone OPimTimeZone::current()
{
QCString str = ::getenv( "TZ" );
@@ -176,13 +178,13 @@ OPimTimeZone OPimTimeZone::current()
return zone;
}
OPimTimeZone OPimTimeZone::utc()
{
- return OPimTimeZone( "UTC" );
+ return OPimTimeZone( "Europe/London" );
}
QString OPimTimeZone::timeZone() const
{
return m_name;