Merge lp:~3v1n0/ubuntu-settings-components/add-months-js-clamping into lp:ubuntu-settings-components

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Lukáš Tinkl
Approved revision: 177
Merged at revision: 175
Proposed branch: lp:~3v1n0/ubuntu-settings-components/add-months-js-clamping
Merge into: lp:ubuntu-settings-components
Diff against target: 99 lines (+55/-6)
3 files modified
plugins/Ubuntu/Settings/Components/Calendar.qml (+1/-1)
plugins/Ubuntu/Settings/Components/dateExt.js (+4/-5)
tests/qmltests/Components/tst_Calendar.qml (+50/-0)
To merge this branch: bzr merge lp:~3v1n0/ubuntu-settings-components/add-months-js-clamping
Reviewer Review Type Date Requested Status
Unity8 CI Bot continuous-integration Approve
Lukáš Tinkl (community) Approve
Review via email: mp+312155@code.launchpad.net

Commit message

dateExt: take care of the numbers of days in month when adding months

We have to clamp to the last day of the month, or JS will go to the next/previous
month automatically when going from a 31-days month to a 28/29/30-days one.

To post a comment you must log in.
176. By Marco Trevisan (Treviño)

dateExt: use just a setMonth call

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:175
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/116/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3431
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/1970
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/1970
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3459
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3306
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3306/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3306
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3306/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3306
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3306/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3306
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3306/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3306
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3306/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3306
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3306/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/116/rebuild

review: Approve (continuous-integration)
Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:176
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/117/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3432
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/1971
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/1971
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3460
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3307
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3307/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3307
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3307/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3307
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3307/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3307
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3307/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3307
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3307/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3307
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3307/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/117/rebuild

review: Approve (continuous-integration)
177. By Marco Trevisan (Treviño)

testCalendar: add tests for addMonths and daysInMonth

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:177
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/118/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3433
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/1972
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/1972
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3461
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3308
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3308/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3308
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3308/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3308
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3308/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3308
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3308/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3308
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3308/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3308
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3308/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/118/rebuild

review: Approve (continuous-integration)
Revision history for this message
Lukáš Tinkl (lukas-kde) wrote :

Yup, calendar still works fine inside a u8 session; tests passing both locally and also in CI.

review: Approve
178. By Marco Trevisan (Treviño)

testCalendar: use Math.floor instead of the | to truncate

Revision history for this message
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:178
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/119/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/3435
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=qmluitests.sh/1973
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/test-0-autopkgtest/label=amd64,release=zesty,testname=qmluitests.sh/1973
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/3463
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3310
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/3310/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3310
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/3310/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3310
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/3310/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3310
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/3310/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3310
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/3310/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3310
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/3310/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-ubuntu-settings-components-ci/119/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Ubuntu/Settings/Components/Calendar.qml'
2--- plugins/Ubuntu/Settings/Components/Calendar.qml 2016-11-22 09:56:00 +0000
3+++ plugins/Ubuntu/Settings/Components/Calendar.qml 2016-11-30 22:43:14 +0000
4@@ -101,7 +101,7 @@
5
6 function __setCurrentDateFromMonth(month) {
7 if (month.equals(priv.today.getMonth())) {
8- currentDate = priv.today.toDate()
9+ currentDate = priv.today.toDate()
10 } else {
11 currentDate = month.toDate()
12 }
13
14=== modified file 'plugins/Ubuntu/Settings/Components/dateExt.js'
15--- plugins/Ubuntu/Settings/Components/dateExt.js 2016-09-06 13:48:32 +0000
16+++ plugins/Ubuntu/Settings/Components/dateExt.js 2016-11-30 22:43:14 +0000
17@@ -13,10 +13,7 @@
18 }
19
20 Date.daysInMonth = function(year, month) {
21- return [
22- 31/*Jan*/, 28/*Feb*/, 31/*Mar*/, 30/*Apr*/, 31/*May*/, 30/*Jun*/,
23- 31/*Jul*/, 31/*Aug*/, 30/*Sep*/, 31/*Oct*/, 30/*Nov*/, 31/*Dec*/
24- ][month] + (month == 1) * Date.leapYear(year)
25+ return new Date(year, month + 1, 0).getDate()
26 }
27
28 Date.prototype.midnight = function() {
29@@ -33,6 +30,8 @@
30
31 Date.prototype.addMonths = function(months) {
32 var date = new Date(this)
33- date.setMonth(date.getMonth() + months)
34+ var targetMonth = date.getMonth() + months
35+ var targetDay = Math.min(date.getDate(), Date.daysInMonth(date.getFullYear(), targetMonth))
36+ date.setMonth(targetMonth, targetDay)
37 return date
38 }
39
40=== modified file 'tests/qmltests/Components/tst_Calendar.qml'
41--- tests/qmltests/Components/tst_Calendar.qml 2016-11-15 17:58:33 +0000
42+++ tests/qmltests/Components/tst_Calendar.qml 2016-11-30 22:43:14 +0000
43@@ -57,6 +57,56 @@
44 calendar.selectedDate = new Date(2013, 4, 10);
45 }
46
47+ function test_daysInMonth_data() {
48+ var tests = []
49+
50+ for (var year = 2000; year <= 2016; ++year) {
51+ for (var month = 1; month <= 12; ++month) {
52+ tests.push({tag: year+"/"+month, year: year, month: month })
53+ }
54+ }
55+
56+ return tests
57+ }
58+
59+ function test_daysInMonth(data) {
60+ switch (data.month) {
61+ case 2:
62+ var expected = Date.leapYear(data.year) ? 29 : 28
63+ break
64+ case 4:
65+ case 6:
66+ case 9:
67+ case 11:
68+ var expected = 30
69+ break
70+ default:
71+ var expected = 31
72+ }
73+
74+ compare(Date.daysInMonth(data.year, data.month-1), expected)
75+ }
76+
77+ function test_addMonthsFromLastDay_data() {
78+ var tests = []
79+ for (var i = 0; i <= 25; ++i) {
80+ tests.push({tag: "previous "+i, delta: -i })
81+ tests.push({tag: "next "+i, delta: i })
82+ }
83+ return tests
84+ }
85+
86+ function test_addMonthsFromLastDay(data) {
87+ var date = new Date(2016, 4, 31)
88+ var newDate = date.addMonths(data.delta)
89+ var monthDelta = date.getMonth() + data.delta
90+ var monthNumber = monthDelta % 12
91+
92+ compare(newDate.getFullYear(), Math.floor(date.getFullYear() + monthDelta / 12))
93+ compare(newDate.getMonth(), monthNumber < 0 ? 12 + monthNumber : monthNumber)
94+ compare(newDate.getDate(), Date.daysInMonth(newDate.getFullYear(), newDate.getMonth()))
95+ }
96+
97 function test_selectedDate_data() {
98 return [
99 { date: new Date(2010, 4, 10) },

Subscribers

People subscribed via source and target branches