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

Proposed by Victor Thompson
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 147
Merged at revision: 145
Proposed branch: lp:~vthompson/ubuntu-weather-app/adjust-sunrise-sunset-tz
Merge into: lp:ubuntu-weather-app
Diff against target: 73 lines (+17/-7)
3 files modified
app/data/WeatherApi.js (+7/-4)
app/ui/LocationPane.qml (+9/-3)
debian/changelog (+1/-0)
To merge this branch: bzr merge lp:~vthompson/ubuntu-weather-app/adjust-sunrise-sunset-tz
Reviewer Review Type Date Requested Status
Andrew Hayzen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+274834@code.launchpad.net

Commit message

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

Description of the change

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

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

Currently, I don't see an easy way of determining if a given location is under daylight savings time. Putting this on hold.

Revision history for this message
Victor Thompson (vthompson) wrote :

Currently this MP works in all cases except when the user's location is in DST and an added location is no longer in DST. For instance, DST ends in Amsterdam on October 25th. For those in the US, a location added for Amsterdam will have the incorrect sunrise/sunset from October 25th until DST ends in the US as well, on November 1st. After this period of disagreement in DST status the times are once again correct.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Ok we are going to land this as is, I'll report a bug later to track the slight gap.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
552 todayDate = date;552 todayDate = date;
553 }553 }
554 tmpResult[day] = _buildDayFormat(date, dayData, nowMs);554 tmpResult[day] = _buildDayFormat(date, dayData, nowMs);
555 var sunrise = new Date(sunRiseSet.rise*1000);555 var timezoneOffset = new Date().getTimezoneOffset();
556 var sunset = new Date(sunRiseSet.set*1000);556 var offset = (location.timezone && location.timezone.dstOffset !== undefined) ? (location.timezone.dstOffset*60 + timezoneOffset)*60*1000: 0
557 tmpResult[day].sunrise = sunrise.toLocaleTimeString();557 var sunrise = new Date(sunRiseSet.rise*1000 + offset);
558 tmpResult[day].sunset = sunset.toLocaleTimeString();558 var sunset = new Date(sunRiseSet.set*1000 + offset);
559 var options = { timeZone: location.timezone.timeZoneId, timeZoneName: 'long' };
560 tmpResult[day].sunrise = sunrise.toLocaleTimeString(Qt.locale().name, options);
561 tmpResult[day].sunset = sunset.toLocaleTimeString(Qt.locale().name, options);
559 }562 }
560 //563 //
561 if(data["forecast"] !== undefined) {564 if(data["forecast"] !== undefined) {
562565
=== 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 @@
140140
141 function getDayData(data) {141 function getDayData(data) {
142 var tempUnits = settings.tempScale === "°C" ? "metric" : "imperial"142 var tempUnits = settings.tempScale === "°C" ? "metric" : "imperial"
143 var timezoneOffset = new Date().getTimezoneOffset();
144 var offset = (data.location.timezone && data.location.timezone.dstOffset !== undefined) ? (data.location.timezone.dstOffset*60 + timezoneOffset)*60*1000: 0
145 var options = { timeZone: data.location.timezone.timeZoneId, timeZoneName: 'long' };
146 var sunrise = new Date(SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunrise.getTime() + offset);
147 var sunset = new Date(SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunset.getTime() + offset);
143148
144 return {149 return {
145 day: formatTimestamp(data.date, 'dddd'),150 day: formatTimestamp(data.date, 'dddd'),
@@ -149,8 +154,8 @@
149 condition: emptyIfUndefined(data.condition),154 condition: emptyIfUndefined(data.condition),
150 chanceOfRain: emptyIfUndefined(data.propPrecip, "%"),155 chanceOfRain: emptyIfUndefined(data.propPrecip, "%"),
151 humidity: emptyIfUndefined(data.humidity, "%"),156 humidity: emptyIfUndefined(data.humidity, "%"),
152 sunrise: data.sunrise || SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunrise.toLocaleTimeString(),157 sunrise: data.sunrise || sunrise.toLocaleTimeString(Qt.locale().name, options),
153 sunset: data.sunset || SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunset.toLocaleTimeString(),158 sunset: data.sunset || sunset.toLocaleTimeString(Qt.locale().name, options),
154 uvIndex: emptyIfUndefined(data.uv),159 uvIndex: emptyIfUndefined(data.uv),
155 wind: data[tempUnits].windSpeed === undefined || data.windDir === undefined160 wind: data[tempUnits].windSpeed === undefined || data.windDir === undefined
156 ? "" : Math.round(data[tempUnits].windSpeed) + settings.windUnits + " " + data.windDir161 ? "" : Math.round(data[tempUnits].windSpeed) + settings.windUnits + " " + data.windDir
@@ -201,10 +206,11 @@
201 hourlyForecasts = hourlyForecasts.concat(forecasts[x].hourly)206 hourlyForecasts = hourlyForecasts.concat(forecasts[x].hourly)
202 }207 }
203208
204 // Copy the coords of the location209 // Copy the coords and timezone of the location
205 // so that sun{rise,set} work with OWM210 // so that sun{rise,set} work with OWM
206 forecasts[x].location = {211 forecasts[x].location = {
207 coord: data.location.coord,212 coord: data.location.coord,
213 timezone: data.location.timezone
208 };214 };
209215
210 if (x === 0) {216 if (x === 0) {
211217
=== 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 @@
30 languages.30 languages.
31 * Show the bottom loading animation (LoadingIndicator) on the LocationsPage. (LP: #1490040)31 * Show the bottom loading animation (LoadingIndicator) on the LocationsPage. (LP: #1490040)
32 * Add FakeHeader component to ease the bottom edge transition.32 * Add FakeHeader component to ease the bottom edge transition.
33 * Use the timezone of the Location to display sunrise/sunset times.
3334
34 [ Andrew Hayzen ]35 [ Andrew Hayzen ]
35 * Add mocked locations for autopilot and add a test using the data36 * Add mocked locations for autopilot and add a test using the data

Subscribers

People subscribed via source and target branches

to all changes: