on xenial help sign in
Remove unused Time.js and its test
commitf8364bcf1eecae074018f2a75d0b86604d934a49 authorAlbert Astals <albert.astals@canonical.com> dateTue 19 Nov 2013, 10:43 (13 years ago) parentf67edec
3 files changed−167
Components/Time.js−49 tests/qmltests/CMakeLists.txt−1 tests/qmltests/Components/tst_TimeLocal.qml−117
Components/Time.jsdeleted−49
@@ -1,49 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−.pragma library
18−
19−var factors = [
20− [ 1000, "a second ago", "in a second", "%1 seconds ago", "in %1 seconds" ],
21− [ 60, "a minute ago", "in a minute", "%1 minutes ago", "in %1 minutes" ],
22− [ 60, "an hour ago", "in an hour", "%1 hours ago", "in %1 hours" ],
23− [ 24, "yesterday", "tomorrow", "%1 days ago", "in %1 days" ],
24− [ 7, "a week ago", "in a week", "about %1 weeks ago", "in about %1 weeks" ],
25− [ 4.35, "a month ago", "in a month", "%1 months ago", "in %1 months" ], // == 365.25 days / 12 months / 7 days
26− [ 12, "a year ago", "in a year", "%1 years ago", "in %1 years" ]
27−]
28−
29−function readableFromNow(date, now) {
30− var then = new Date(date);
31− if (isNaN(then)) return "";
32− if (now === undefined) {
33− now = new Date();
34− } else if (isNaN(now)) throw "now is NaN";
35− var diff = Math.abs(now - then);
36− if (diff < 1000) return "just now";
37−
38− var future = now < then;
39− var humanDiff;
40− for (var k in factors) {
41− diff /= factors[k][0];
42− if (Math.floor(diff) == 1) {
43− humanDiff = factors[k][future ? 2 : 1];
44− } else if (Math.floor(diff) > 1) {
45− humanDiff = factors[k][future ? 4 : 3].arg(Math.round(diff));
46− } else break;
47− }
48− return humanDiff;
49−}
tests/qmltests/CMakeLists.txt−1
@@ -15,7 +15,6 @@ add_qml_test(Components AnimationControllerWithSignals)
1515add_qml_test(Components Carousel)
1616add_qml_test(Components OpenEffect)
1717add_qml_test(Components RatingStars)
18−add_qml_test(Components TimeLocal)
1918add_qml_test(Panel IndicatorItem)
2019add_qml_test(utils/Unity/Test UnityTest)
2120
tests/qmltests/Components/tst_TimeLocal.qmldeleted−117
@@ -1,117 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.0
18−import QtTest 1.0
19−import "../../../Components/Time.js" as TimeLocal
20−
21−TestCase {
22− name: "TimeLocal"
23−
24− property var readableDate
25−
26− function test_readableFromNow_dateUndefined() {
27− readableDate = TimeLocal.readableFromNow()
28− compare(readableDate, "", "readable date should have been null")
29− }
30−
31− function test_readableFromNow_dateNaN() {
32− readableDate = TimeLocal.readableFromNow("this is a string, not a date")
33− compare(readableDate, "", "readable date should have been null")
34− }
35−
36− function test_readableFromNow_justNow() {
37− readableDate = TimeLocal.readableFromNow(new Date())
38− compare(readableDate, "just now", "readable date should have been now")
39− }
40−
41− function test_readableFromNow_nowNaN() {
42− var fail = false
43− try {
44− TimeLocal.readableFromNow(new Date(), "this is a string, not a date")
45− } catch (err) {
46− fail = true
47− } finally {
48− compare(fail, true, "readable date should have thrown an exception")
49− }
50− }
51−
52− function cycleTime(diff, previous, next, units, endIterator) {
53− var now = new Date()
54− var time = now.getTime()
55− readableDate = TimeLocal.readableFromNow(time - diff, now)
56− compare(readableDate, previous, "different time predicted")
57− readableDate = TimeLocal.readableFromNow(time + diff, now)
58− compare(readableDate, next, "different time predicted")
59− for (var i = 2; i < endIterator; i++) {
60− var tmpDiff = i * diff
61− readableDate = TimeLocal.readableFromNow(time - tmpDiff, now)
62− compare(readableDate, i + " " + units + " ago", "different time predicted")
63− readableDate = TimeLocal.readableFromNow(time + tmpDiff, now)
64− compare(readableDate, "in " + i + " " + units, "different time predicted")
65− }
66− }
67−
68− function test_readableFromNow_seconds() {
69− cycleTime(1000, "a second ago", "in a second", "seconds", 60)
70− }
71−
72− function test_readableFromNow_minutes() {
73− cycleTime(1000 * 60, "a minute ago", "in a minute", "minutes", 60)
74− }
75−
76− function test_readableFromNow_hours() {
77− cycleTime(1000 * 60 * 60, "an hour ago", "in an hour", "hours", 24)
78− }
79−
80− function test_readableFromNow_days() {
81− cycleTime(1000 * 60 * 60 * 24, "yesterday", "tomorrow", "days", 7)
82− }
83−
84− function test_readableFromNow_weeks() {
85− var now = new Date()
86− for (var i = 7; i < 30; i++) {
87− readableDate = TimeLocal.readableFromNow(now.getTime() - i * 1000 * 60 * 60 * 24, now)
88− if (i < 14)
89− compare(readableDate, "a week ago", "different time predicted")
90− else if (i < 18)
91− compare(readableDate, "about 2 weeks ago", "different time predicted")
92− else if (i < 25)
93− compare(readableDate, "about 3 weeks ago", "different time predicted")
94− else
95− compare(readableDate, "about 4 weeks ago", "different time predicted")
96− }
97− for (var i = 7; i < 30; i++) {
98− readableDate = TimeLocal.readableFromNow(now.getTime() + i * 1000 * 60 * 60 * 24, now)
99− if (i < 14)
100− compare(readableDate, "in a week", "different time predicted")
101− else if (i < 18)
102− compare(readableDate, "in about 2 weeks", "different time predicted")
103− else if (i < 25)
104− compare(readableDate, "in about 3 weeks", "different time predicted")
105− else
106− compare(readableDate, "in about 4 weeks", "different time predicted")
107− }
108− }
109−
110− function test_readableFromNow_months() {
111− cycleTime(1000 * 60 * 60 * 24 * 30.45, "a month ago", "in a month", "months", 12)
112− }
113−
114− function test_readableFromNow_years() {
115− cycleTime(1000 * 60 * 60 * 24 * 366, "a year ago", "in a year", "years", 5)
116− }
117−}