Merge lp:~zsombi/ubuntu-ui-toolkit/alarm-date-fix into lp:ubuntu-ui-toolkit

Proposed by Zsombor Egri
Status: Superseded
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/alarm-date-fix
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~zsombi/ubuntu-ui-toolkit/alarm-fetch-fix
Diff against target: 137 lines (+50/-6)
3 files modified
modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp (+9/-5)
modules/Ubuntu/Components/plugin/alarmmanager_p.h (+8/-0)
tests/unit/tst_alarms/tst_alarms.cpp (+33/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/alarm-date-fix
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+210181@code.launchpad.net

This proposal has been superseded by a proposal from 2014-04-10.

Commit message

Fix for alarm dates to occur in the same time in all timezones.

Description of the change

Fix for alarm dates to occur in the same time in all timezones.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

So on testing this MP using the ubuntu-clock-app, I have the following observations.

1. Alarms created in the local tz are saved and properly triggered at the correct time. The correct time is also displayed in the indicator-datetime. Hence one can say that the bug #1283236 is fixed.

2. If I switch from UTC+1 (netherlands) to UTC (london) using the system settings app and then create an alarm for say 11:00 AM, it gets saved as 10:00 AM in the clock app. The indicator also shows the alarm as 10:00 AM. The alarm does *not* trigger at 10:00 AM however.

3. If I perform observation #2 but restart the phone after changing the locale, then things work as expected meaning an alarm saved at 11:00 AM gets triggered at 11:00 AM, shown in the indicator as 11:00 AM as well.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

I tested this MP since it also includes the MP at https://code.launchpad.net/~zsombi/ubuntu-ui-toolkit/alarm-fetch-fix/+merge/208749. On testing it, here are my observations.

1. Bug #1283236 is fixed. Alarms saved in local tz are triggered in local tz.

2. Bug #1283859 is not fixed. Editing and saving alarms (both single and recurring) doesn't update the alarm time shown in the indicator. The alarm also rings at the original time and not at the updated time.

3. Bug #1285958 Recurring alarms can now be saved on sundays :)

Revision history for this message
Zsombor Egri (zsombi) wrote :

> I tested this MP since it also includes the MP at
> https://code.launchpad.net/~zsombi/ubuntu-ui-toolkit/alarm-fetch-
> fix/+merge/208749. On testing it, here are my observations.
>
> 1. Bug #1283236 is fixed. Alarms saved in local tz are triggered in local tz.
>
> 2. Bug #1283859 is not fixed. Editing and saving alarms (both single and
> recurring) doesn't update the alarm time shown in the indicator. The alarm
> also rings at the original time and not at the updated time.

Removed attach to the bug as it doesn't seem to be related to Alarm API.

>
> 3. Bug #1285958 Recurring alarms can now be saved on sundays :)

Revision history for this message
Cris Dywan (kalikiana) wrote :

Should be a good idea to have a small test case for transcodeDate, even if it's internal, to be sure it works as expected.

review: Needs Fixing
Revision history for this message
Zsombor Egri (zsombi) wrote :

> Should be a good idea to have a small test case for transcodeDate, even if
> it's internal, to be sure it works as expected.

Test case added.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Thanks!

review: Approve
980. By Zsombor Egri

prereq merge

981. By Zsombor Egri

prereq merge

982. By Zsombor Egri

prereq merge

983. By Zsombor Egri

staging merge

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp'
--- modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp 2014-04-10 09:53:40 +0000
+++ modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp 2014-04-10 09:53:40 +0000
@@ -119,7 +119,7 @@
119119
120 int type, days;120 int type, days;
121 in >> alarm.message >> alarm.date >> alarm.sound >> type >> days >> alarm.enabled;121 in >> alarm.message >> alarm.date >> alarm.sound >> type >> days >> alarm.enabled;
122 alarm.originalDate = alarm.date;122 alarm.originalDate = alarm.date = AlarmData::transcodeDate(alarm.date, Qt::LocalTime);
123 alarm.type = static_cast<UCAlarm::AlarmType>(type);123 alarm.type = static_cast<UCAlarm::AlarmType>(type);
124 alarm.days = static_cast<UCAlarm::DaysOfWeek>(days);124 alarm.days = static_cast<UCAlarm::DaysOfWeek>(days);
125125
@@ -148,7 +148,7 @@
148148
149 Q_FOREACH(const AlarmData &alarm, alarmList) {149 Q_FOREACH(const AlarmData &alarm, alarmList) {
150 out << alarm.message150 out << alarm.message
151 << alarm.originalDate151 << AlarmData::transcodeDate(alarm.originalDate, Qt::UTC)
152 << alarm.sound152 << alarm.sound
153 << alarm.type153 << alarm.type
154 << alarm.days154 << alarm.days
@@ -162,7 +162,7 @@
162{162{
163 event.setCollectionId(collection.id());163 event.setCollectionId(collection.id());
164 event.setAllDay(false);164 event.setAllDay(false);
165 event.setStartDateTime(alarm.date);165 event.setStartDateTime(AlarmData::transcodeDate(alarm.date, Qt::UTC));
166 event.setDisplayLabel(alarm.message);166 event.setDisplayLabel(alarm.message);
167167
168 if (alarm.enabled) {168 if (alarm.enabled) {
@@ -229,7 +229,7 @@
229229
230 alarm.cookie = QVariant::fromValue<QOrganizerItemId>(event.id());230 alarm.cookie = QVariant::fromValue<QOrganizerItemId>(event.id());
231 alarm.message = event.displayLabel();231 alarm.message = event.displayLabel();
232 alarm.date = AlarmData::normalizeDate(event.startDateTime());232 alarm.date = AlarmData::transcodeDate(event.startDateTime().toUTC(), Qt::LocalTime);
233 alarm.sound = QUrl(event.description());233 alarm.sound = QUrl(event.description());
234 alarm.originalDate = alarm.date;234 alarm.originalDate = alarm.date;
235235
@@ -355,6 +355,10 @@
355 endDate = startDate.addDays(8);355 endDate = startDate.addDays(8);
356 }356 }
357357
358 // transcode both dates
359 startDate = AlarmData::transcodeDate(startDate, Qt::UTC);
360 endDate = AlarmData::transcodeDate(endDate, Qt::UTC);
361
358 QList<QOrganizerItem> occurrences = manager->itemOccurrences(event, startDate, endDate, 10);362 QList<QOrganizerItem> occurrences = manager->itemOccurrences(event, startDate, endDate, 10);
359 // get the first occurrence and use the date from it363 // get the first occurrence and use the date from it
360 if ((occurrences.length() > 0) && (occurrences[0].type() == QOrganizerItemType::TypeTodoOccurrence)) {364 if ((occurrences.length() > 0) && (occurrences[0].type() == QOrganizerItemType::TypeTodoOccurrence)) {
@@ -364,7 +368,7 @@
364 // check if the date is after the current datetime368 // check if the date is after the current datetime
365 // the first occurrence is the one closest to the currentDate, therefore we can safely369 // the first occurrence is the one closest to the currentDate, therefore we can safely
366 // set that startDate to the alarm370 // set that startDate to the alarm
367 alarm.date = occurrence.startDateTime();371 alarm.date = AlarmData::transcodeDate(occurrence.startDateTime().toUTC(), Qt::LocalTime);
368 if (alarm.date > currentDate) {372 if (alarm.date > currentDate) {
369 // we have the proper date set, leave373 // we have the proper date set, leave
370 break;374 break;
371375
=== modified file 'modules/Ubuntu/Components/plugin/alarmmanager_p.h'
--- modules/Ubuntu/Components/plugin/alarmmanager_p.h 2014-04-10 09:53:40 +0000
+++ modules/Ubuntu/Components/plugin/alarmmanager_p.h 2014-04-10 09:53:40 +0000
@@ -101,6 +101,14 @@
101 return QDateTime(dt.date(), time, dt.timeSpec());101 return QDateTime(dt.date(), time, dt.timeSpec());
102 }102 }
103103
104 // the function normalizes and transcodes the date into UTC/LocalTime equivalent
105 static QDateTime transcodeDate(const QDateTime &dt, Qt::TimeSpec targetSpec) {
106 if (dt.timeSpec() == targetSpec) {
107 return normalizeDate(dt);
108 }
109 return QDateTime(dt.date(), normalizeDate(dt).time(), targetSpec);
110 }
111
104 unsigned int changes;112 unsigned int changes;
105 QVariant cookie;113 QVariant cookie;
106114
107115
=== modified file 'tests/unit/tst_alarms/tst_alarms.cpp'
--- tests/unit/tst_alarms/tst_alarms.cpp 2014-04-10 09:53:40 +0000
+++ tests/unit/tst_alarms/tst_alarms.cpp 2014-04-10 09:53:40 +0000
@@ -31,6 +31,7 @@
31#include <QtCore/QDebug>31#include <QtCore/QDebug>
32#include <QtTest/QTest>32#include <QtTest/QTest>
33#include <QtTest/QSignalSpy>33#include <QtTest/QSignalSpy>
34#include <QtCore/QTimeZone>
3435
35class tst_UCAlarms : public QObject36class tst_UCAlarms : public QObject
36{37{
@@ -126,7 +127,7 @@
126 }127 }
127128
128 void test_singleShotAlarmPass() {129 void test_singleShotAlarmPass() {
129 UCAlarm alarm(QDateTime::currentDateTime().addSecs(10), "test_singleShotAlarmPass");130 UCAlarm alarm(QDateTime::currentDateTime().addSecs(4), "test_singleShotAlarmPass");
130 alarm.save();131 alarm.save();
131 waitForRequest(&alarm);132 waitForRequest(&alarm);
132 QCOMPARE(alarm.error(), (int)UCAlarm::NoError);133 QCOMPARE(alarm.error(), (int)UCAlarm::NoError);
@@ -424,6 +425,37 @@
424 QVERIFY(containsAlarm(&nextAlarm));425 QVERIFY(containsAlarm(&nextAlarm));
425 }426 }
426427
428 void test_transcodeDate_data()
429 {
430 QTest::addColumn<QDateTime>("date");
431 QTest::addColumn<int>("srcSpec");
432 QTest::addColumn<int>("dstSpec");
433 QTest::addColumn<bool>("xfail");
434
435 QDateTime now = QDateTime::currentDateTime();
436 QTest::newRow("Local to Local") << now << (int)Qt::LocalTime << (int)Qt::LocalTime << true;
437 QTest::newRow("Local to UTC") << now << (int)Qt::LocalTime << (int)Qt::UTC << false;
438 QTest::newRow("UTC to UTC") << now << (int)Qt::UTC << (int)Qt::UTC << true;
439 QTest::newRow("UTC to Local") << now << (int)Qt::UTC << (int)Qt::LocalTime << false;
440 }
441
442 void test_transcodeDate()
443 {
444 QFETCH(QDateTime, date);
445 QFETCH(int, srcSpec);
446 QFETCH(int, dstSpec);
447 QFETCH(bool, xfail);
448
449 QDateTime srcDate = AlarmData::normalizeDate(QDateTime(date.date(), date.time(), (Qt::TimeSpec)srcSpec));
450 QDateTime dstDate(AlarmData::transcodeDate(srcDate, (Qt::TimeSpec)dstSpec));
451 QCOMPARE(srcDate.date(), dstDate.date());
452 QCOMPARE(srcDate.time(), dstDate.time());
453 if (xfail) {
454 QEXPECT_FAIL("", "Similar timespec set, expect fail", Continue);
455 }
456 QVERIFY(srcDate.timeZone() != dstDate.timeZone());
457 }
458
427};459};
428460
429QTEST_MAIN(tst_UCAlarms)461QTEST_MAIN(tst_UCAlarms)

Subscribers

People subscribed via source and target branches

to status/vote changes: