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

Proposed by Victor Thompson on 2015-10-18
Status: Merged
Approved by: Andrew Hayzen on 2015-10-20
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 2015-10-18 Approve on 2015-10-20
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2015-10-20
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.
review: Approve (continuous-integration)
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.

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.

review: Approve (continuous-integration)
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
1=== modified file 'app/data/WeatherApi.js'
2--- app/data/WeatherApi.js 2015-10-14 23:53:23 +0000
3+++ app/data/WeatherApi.js 2015-10-20 01:39:21 +0000
4@@ -552,10 +552,13 @@
5 todayDate = date;
6 }
7 tmpResult[day] = _buildDayFormat(date, dayData, nowMs);
8- var sunrise = new Date(sunRiseSet.rise*1000);
9- var sunset = new Date(sunRiseSet.set*1000);
10- tmpResult[day].sunrise = sunrise.toLocaleTimeString();
11- tmpResult[day].sunset = sunset.toLocaleTimeString();
12+ var timezoneOffset = new Date().getTimezoneOffset();
13+ var offset = (location.timezone && location.timezone.dstOffset !== undefined) ? (location.timezone.dstOffset*60 + timezoneOffset)*60*1000: 0
14+ var sunrise = new Date(sunRiseSet.rise*1000 + offset);
15+ var sunset = new Date(sunRiseSet.set*1000 + offset);
16+ var options = { timeZone: location.timezone.timeZoneId, timeZoneName: 'long' };
17+ tmpResult[day].sunrise = sunrise.toLocaleTimeString(Qt.locale().name, options);
18+ tmpResult[day].sunset = sunset.toLocaleTimeString(Qt.locale().name, options);
19 }
20 //
21 if(data["forecast"] !== undefined) {
22
23=== modified file 'app/ui/LocationPane.qml'
24--- app/ui/LocationPane.qml 2015-10-15 14:15:10 +0000
25+++ app/ui/LocationPane.qml 2015-10-20 01:39:21 +0000
26@@ -140,6 +140,11 @@
27
28 function getDayData(data) {
29 var tempUnits = settings.tempScale === "°C" ? "metric" : "imperial"
30+ var timezoneOffset = new Date().getTimezoneOffset();
31+ var offset = (data.location.timezone && data.location.timezone.dstOffset !== undefined) ? (data.location.timezone.dstOffset*60 + timezoneOffset)*60*1000: 0
32+ var options = { timeZone: data.location.timezone.timeZoneId, timeZoneName: 'long' };
33+ var sunrise = new Date(SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunrise.getTime() + offset);
34+ var sunset = new Date(SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunset.getTime() + offset);
35
36 return {
37 day: formatTimestamp(data.date, 'dddd'),
38@@ -149,8 +154,8 @@
39 condition: emptyIfUndefined(data.condition),
40 chanceOfRain: emptyIfUndefined(data.propPrecip, "%"),
41 humidity: emptyIfUndefined(data.humidity, "%"),
42- sunrise: data.sunrise || SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunrise.toLocaleTimeString(),
43- sunset: data.sunset || SunCalc.SunCalc.getTimes(getDate(data.date), data.location.coord.lat, data.location.coord.lon).sunset.toLocaleTimeString(),
44+ sunrise: data.sunrise || sunrise.toLocaleTimeString(Qt.locale().name, options),
45+ sunset: data.sunset || sunset.toLocaleTimeString(Qt.locale().name, options),
46 uvIndex: emptyIfUndefined(data.uv),
47 wind: data[tempUnits].windSpeed === undefined || data.windDir === undefined
48 ? "" : Math.round(data[tempUnits].windSpeed) + settings.windUnits + " " + data.windDir
49@@ -201,10 +206,11 @@
50 hourlyForecasts = hourlyForecasts.concat(forecasts[x].hourly)
51 }
52
53- // Copy the coords of the location
54+ // Copy the coords and timezone of the location
55 // so that sun{rise,set} work with OWM
56 forecasts[x].location = {
57 coord: data.location.coord,
58+ timezone: data.location.timezone
59 };
60
61 if (x === 0) {
62
63=== modified file 'debian/changelog'
64--- debian/changelog 2015-10-18 15:51:11 +0000
65+++ debian/changelog 2015-10-20 01:39:21 +0000
66@@ -30,6 +30,7 @@
67 languages.
68 * Show the bottom loading animation (LoadingIndicator) on the LocationsPage. (LP: #1490040)
69 * Add FakeHeader component to ease the bottom edge transition.
70+ * Use the timezone of the Location to display sunrise/sunset times.
71
72 [ Andrew Hayzen ]
73 * Add mocked locations for autopilot and add a test using the data

Subscribers

People subscribed via source and target branches

to all changes: