← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~gang65/ubuntu-clock-app/ubuntu-clock-app-alarm-description-fix into lp:ubuntu-clock-app

 

Bartosz Kosiorek has proposed merging lp:~gang65/ubuntu-clock-app/ubuntu-clock-app-alarm-description-fix into lp:ubuntu-clock-app.

Commit message:
Fix alarm difference time description, during DST change (LP: #1510694)


Requested reviews:
  Jenkins Bot (ubuntu-core-apps-jenkins-bot): continuous-integration
  Ubuntu Clock Developers (ubuntu-clock-dev)
Related bugs:
  Bug #1510694 in Ubuntu Clock App: " Alarm description are always "Alarm passed",  during first hour of DST change."
  https://bugs.launchpad.net/ubuntu-clock-app/+bug/1510694

For more details, see:
https://code.launchpad.net/~gang65/ubuntu-clock-app/ubuntu-clock-app-alarm-description-fix/+merge/275932

Fix alarm difference time description, during DST change (LP: #1510694)

-- 
Your team Ubuntu Clock Developers is requested to review the proposed merge of lp:~gang65/ubuntu-clock-app/ubuntu-clock-app-alarm-description-fix into lp:ubuntu-clock-app.
=== modified file 'app/alarm/AlarmDelegate.qml'
--- app/alarm/AlarmDelegate.qml	2015-10-16 07:38:33 +0000
+++ app/alarm/AlarmDelegate.qml	2015-10-27 22:54:00 +0000
@@ -88,7 +88,7 @@
                 visible: !(type === Alarm.OneTime && !model.enabled)
                 elide: Text.ElideRight
                 text: type === Alarm.Repeating ? alarmUtils.format_day_string(daysOfWeek, type)
-                                               : model.enabled ? alarmUtils.get_time_to_next_alarm(model.date - localTime)
+                                               : model.enabled ? alarmUtils.get_time_to_alarm(model.date, localTime)
                                                                : "Alarm Disabled"
 
                 function animateTextChange() {
@@ -107,7 +107,7 @@
 
                     ScriptAction {
                         script: alarmSubtitle.text = showAlarmFrequency ? alarmUtils.format_day_string(daysOfWeek, type)
-                                                                        : alarmUtils.get_time_to_next_alarm(model.date - localTime)
+                                                                        : alarmUtils.get_time_to_alarm(model.date, localTime)
                     }
 
                     PropertyAnimation {

=== modified file 'app/alarm/AlarmUtils.qml'
--- app/alarm/AlarmUtils.qml	2015-10-08 21:49:48 +0000
+++ app/alarm/AlarmUtils.qml	2015-10-27 22:54:00 +0000
@@ -79,12 +79,26 @@
           return bottom_edge_title
         }
 
-        bottom_edge_title = i18n.tr("Next Alarm %1").arg(get_time_to_next_alarm(activeAlarmDate - clockTime))
+        bottom_edge_title = i18n.tr("Next Alarm %1").arg(get_time_to_alarm(activeAlarmDate, clockTime))
         return bottom_edge_title
     }
 
-    // Function to format the time to next alarm into a string
-    function get_time_to_next_alarm(totalTime) {
+    function get_utc_time(dateTime) {
+        return new Date(dateTime.getUTCFullYear(),
+                        dateTime.getUTCMonth(),
+                        dateTime.getUTCDate(),
+                        dateTime.getUTCHours(),
+                        dateTime.getUTCMinutes(),
+                        dateTime.getUTCSeconds(),
+                        dateTime.getUTCMilliseconds())
+    }
+
+    // Function to format the time to specific alarm into a string
+    function get_time_to_alarm(alarmDate, currentDateTime) {
+        // Discard the time and time-zone information, so it will be properly calculate time,
+        // even with different timezones (eg. during daylight saving change)
+        var totalTime = get_utc_time(alarmDate) - get_utc_time(currentDateTime);
+
         if(totalTime < 0) {
             return i18n.tr("Alarm Passed")
         }

=== modified file 'debian/changelog'
--- debian/changelog	2015-10-16 05:58:01 +0000
+++ debian/changelog	2015-10-27 22:54:00 +0000
@@ -1,4 +1,11 @@
-ubuntu-clock-app (3.6) UNRELEASED; urgency=medium
+ubuntu-clock-app (3.7) UNRELEASED; urgency=medium
+
+  [ Bartosz Kosiorek ]
+  * Fix alarm difference time description, during DST change (LP: #1510694)
+
+ -- Bartosz Kosiorek <gang65@xxxxxxxxxxxxxx>  Tue, 27 Oct 2015 23:49:19 +0100
+
+ubuntu-clock-app (3.6)  vivid; urgency=medium
 
   [ Nekhelesh Ramananthan ]
   * Bumped version to 3.6

=== modified file 'tests/unit/tst_alarm.qml'
--- tests/unit/tst_alarm.qml	2015-09-17 06:28:20 +0000
+++ tests/unit/tst_alarm.qml	2015-10-27 22:54:00 +0000
@@ -65,13 +65,16 @@
             //delete all current alarms
             waitForRendering(alarmPage)
             var alarmsList = findChild(alarmPage, "alarmListView")
-            verify(alarmsList != null)
+            verify(alarmsList !== null)
             print("Found " + alarmsList.count + " pre-existing alarms")
 
             for (var i=0; i<alarmsList.count; i++) {
-                print("Deleting Alarm " + i)
+
                 var alarmObject = findChild(alarmsList, "alarm"+i)
-                swipeToDeleteItem(alarmObject)
+                if (alarmObject !== null) {
+                    print("Deleting Alarm " + i)
+                    swipeToDeleteItem(alarmObject)
+                }
                 waitForRendering(alarmPage)
             }
         }

=== modified file 'tests/unit/tst_alarmUtils.qml'
--- tests/unit/tst_alarmUtils.qml	2015-10-08 20:17:11 +0000
+++ tests/unit/tst_alarmUtils.qml	2015-10-27 22:54:00 +0000
@@ -25,9 +25,7 @@
     id: alarmUtilsTest
     name: "AlarmUtilsLibrary"
 
-    property var futureTime: new Date()
-    property var currentTime: new Date()
-    property var mock_notLocalizedDateTimeString: ""
+    property string mock_notLocalizedDateTimeString: ""
 
     AlarmUtils {
         id: alarmUtils
@@ -45,6 +43,9 @@
          Alarm1, currentTime+2hrs, not enabled
          Alarm2, currentTime+7hrs, enabled
         */
+
+        var currentTime = new Date()
+        var futureTime = new Date()
         futureTime.setHours((futureTime.getHours() + 2))
         mockAlarmDatabase.append({"name": "Alarm1", "date": futureTime, "enabled": false})
         futureTime.setHours((futureTime.getHours() + 5))
@@ -96,35 +97,42 @@
     }
 
     /*
-     This test checks if the get_time_to_next_alarm() function takes a time in
+     This test checks if the get_time_to_alarm() function takes a time in
      milliseconds and writtens a user readable string e.g "in 2d 15h 10m" after
      correct calculation.
     */
     function test_timeToNextAlarmStringMustShowAll() {
-        var timeInMilliseconds = 440100000; // 5 days, 2 hrs, 16 mins
-        var result = alarmUtils.get_time_to_next_alarm(timeInMilliseconds)
+        var currentDateTime = new Date()
+        var timeInMilliseconds = ((5 * 24 + 2)* 60 + 15) * 60 * 1000; // 5 days, 2 hrs, 16 mins
+
+        var alarmDate = new Date(currentDateTime.getTime() + timeInMilliseconds);
+        var result = alarmUtils.get_time_to_alarm(alarmDate, currentDateTime)
         compare(result, "in 5d 2h 16m", "Time to next alarm string is incorrect")
     }
 
     /*
-     This test checks if the get_time_to_next_alarm() function takes a time in
+     This test checks if the get_time_to_alarm() function takes a time in
      milliseconds and writtens a user readable string without days e.g "in 15h 10m"
      after correct calculation.
     */
     function test_timeToNextAlarmStringMustNotShowDays() {
-        var timeInMilliseconds = 36000000 // 10 hours, 1 min
-        var result = alarmUtils.get_time_to_next_alarm(timeInMilliseconds)
+        var timeInMilliseconds = 10 * 60 * 60 * 1000 // 10 hours, 1 min
+        var currentDateTime = new Date()
+        var alarmDate = new Date(currentDateTime.getTime() + timeInMilliseconds);
+        var result = alarmUtils.get_time_to_alarm(alarmDate, currentDateTime)
         compare(result, "in 10h 1m", "Time to next alarm string is incorrect")
     }
 
     /*
-     This test checks if the get_time_to_next_alarm() function takes a time in
+     This test checks if the get_time_to_alarm() function takes a time in
      milliseconds and writtens a user readable string with only mins e.g "in 10m"
      after correct calculation.
     */
     function test_timeToNextAlarmStringMustOnlyShowMinutes() {
-        var timeInMilliseconds = 1080000 // 19 mins
-        var result = alarmUtils.get_time_to_next_alarm(timeInMilliseconds)
+        var timeInMilliseconds = 18 * 60 * 1000 // 19 mins
+        var currentDateTime = new Date()
+        var alarmDate = new Date(currentDateTime.getTime() + timeInMilliseconds);
+        var result = alarmUtils.get_time_to_alarm(alarmDate, currentDateTime)
         compare(result, "in 19m", "Time to next alarm string is incorrect")
     }