@@ -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−}