← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~vthompson/ubuntu-weather-app/adjust-sunrise-sunset-tz into lp:ubuntu-weather-app/reboot

 

Victor Thompson has proposed merging lp:~vthompson/ubuntu-weather-app/adjust-sunrise-sunset-tz into lp:ubuntu-weather-app/reboot.

Commit message:
* Use the timezone of the Location to display sunrise/sunset times.

Requested reviews:
  Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot): continuous-integration
  Ubuntu Weather Developers (ubuntu-weather-dev)

For more details, see:
https://code.launchpad.net/~vthompson/ubuntu-weather-app/adjust-sunrise-sunset-tz/+merge/274834

* Use the timezone of the Location to display sunrise/sunset times.
-- 
Your team Ubuntu Weather Developers is requested to review the proposed merge of lp:~vthompson/ubuntu-weather-app/adjust-sunrise-sunset-tz into lp:ubuntu-weather-app/reboot.
=== modified file 'app/data/WeatherApi.js'
--- app/data/WeatherApi.js	2015-10-14 23:53:23 +0000
+++ app/data/WeatherApi.js	2015-10-20 01:39:21 +0000
@@ -552,10 +552,13 @@
                 todayDate = date;
             }
             tmpResult[day] = _buildDayFormat(date, dayData, nowMs);
-            var sunrise = new Date(sunRiseSet.rise*1000);
-            var sunset = new Date(sunRiseSet.set*1000);
-            tmpResult[day].sunrise = sunrise.toLocaleTimeString();
-            tmpResult[day].sunset = sunset.toLocaleTimeString();
+            var timezoneOffset = new Date().getTimezoneOffset();
+            var offset = (location.timezone && location.timezone.dstOffset !== undefined) ? (location.timezone.dstOffset*60 + timezoneOffset)*60*1000: 0
+            var sunrise = new Date(sunRiseSet.rise*1000 + offset);
+            var sunset = new Date(sunRiseSet.set*1000 + offset);
+            var options = { timeZone: location.timezone.timeZoneId, timeZoneName: 'long' };
+            tmpResult[day].sunrise = sunrise.toLocaleTimeString(Qt.locale().name, options);
+            tmpResult[day].sunset = sunset.toLocaleTimeString(Qt.locale().name, options);
         }
         //
         if(data["forecast"] !== undefined) {

=== modified file 'app/ui/LocationPane.qml'
--- app/ui/LocationPane.qml	2015-10-15 14:15:10 +0000
+++ app/ui/LocationPane.qml	2015-10-20 01:39:21 +0000
@@ -140,6 +140,11 @@
 
     function getDayData(data) {
         var tempUnits = settings.tempScale === "°C" ? "metric" : "imperial"
+        var timezoneOffset = new Date().getTimezoneOffset();
+        var offset = (data.location.timezone && data.location.timezone.dstOffset !== undefined) ? (data.location.timezone.dstOffset*60 + timezoneOffset)*60*1000: 0
+        var options = { timeZone: data.location.timezone.timeZoneId, timeZoneName: 'long' };
+        var sunrise = new Date(SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunrise.getTime() + offset);
+        var sunset = new Date(SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunset.getTime() + offset);
 
         return {
             day: formatTimestamp(data.date, 'dddd'),
@@ -149,8 +154,8 @@
             condition: emptyIfUndefined(data.condition),
             chanceOfRain: emptyIfUndefined(data.propPrecip, "%"),
             humidity: emptyIfUndefined(data.humidity, "%"),
-            sunrise: data.sunrise || SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunrise.toLocaleTimeString(),
-            sunset: data.sunset || SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunset.toLocaleTimeString(),
+            sunrise: data.sunrise || sunrise.toLocaleTimeString(Qt.locale().name, options),
+            sunset: data.sunset || sunset.toLocaleTimeString(Qt.locale().name, options),
             uvIndex: emptyIfUndefined(data.uv),
             wind: data[tempUnits].windSpeed === undefined || data.windDir === undefined
                         ? "" : Math.round(data[tempUnits].windSpeed) + settings.windUnits + " " + data.windDir
@@ -201,10 +206,11 @@
                     hourlyForecasts = hourlyForecasts.concat(forecasts[x].hourly)
                 }
 
-                // Copy the coords of the location
+                // Copy the coords and timezone of the location
                 // so that sun{rise,set} work with OWM
                 forecasts[x].location = {
                     coord: data.location.coord,
+                    timezone: data.location.timezone
                 };
 
                 if (x === 0) {

=== modified file 'debian/changelog'
--- debian/changelog	2015-10-18 15:51:11 +0000
+++ debian/changelog	2015-10-20 01:39:21 +0000
@@ -30,6 +30,7 @@
     languages.
   * Show the bottom loading animation (LoadingIndicator) on the LocationsPage. (LP: #1490040)
   * Add FakeHeader component to ease the bottom edge transition.
+  * Use the timezone of the Location to display sunrise/sunset times.
 
   [ Andrew Hayzen ]
   * Add mocked locations for autopilot and add a test using the data


Follow ups