forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_helpers.js
121 lines (96 loc) · 7.06 KB
/
view_helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
QUnit.test("time_duration_hh_mm", assert => {
let func = App.ViewHelpers.time_duration_hh_mm
assert.equal(func(1), '00:01')
assert.equal(func(61), '01:01')
assert.equal(func(3600), '60:00')
assert.equal(func(7200), '120:00')
})
QUnit.test("time_duration", assert => {
let func = App.ViewHelpers.time_duration
assert.equal(func(1), '00:01')
assert.equal(func(61), '01:01')
assert.equal(func(3600), '1:00:00')
assert.equal(func(7200), '2:00:00')
assert.equal(func(36000), '10:00:00')
assert.equal(func(360101), '100:01:41')
})
QUnit.test('relative_time', assert => {
let func = App.ViewHelpers.relative_time
clock = sinon.useFakeTimers({ now: new Date('2022-11-15T10:00:00.000Z') })
assert.equal(func(1, 'minute'), '2022-11-15T10:01:00.000Z')
assert.equal(func(5, 'hour'), '2022-11-15T15:00:00.000Z')
assert.equal(func(3, 'day'), '2022-11-18T10:00:00.000Z')
assert.equal(func(4, 'week'), '2022-12-13T10:00:00.000Z')
assert.equal(func(8, 'month'), '2023-07-15T09:00:00.000Z')
assert.equal(func(2, 'year'), '2024-11-15T10:00:00.000Z')
clock.restore()
})
QUnit.test('relative_time - setMonth() sanity check', assert => {
let func = App.ViewHelpers.relative_time
clock = sinon.useFakeTimers({ now: new Date('2023-01-01T12:00:00.000Z') })
assert.equal(func(1, 'month'), '2023-02-01T12:00:00.000Z', '1st of the month - 1 month')
assert.equal(func(2, 'month'), '2023-03-01T12:00:00.000Z', '1st of the month - 2 months')
assert.equal(func(3, 'month'), '2023-04-01T11:00:00.000Z', '1st of the month - 3 months')
assert.equal(func(4, 'month'), '2023-05-01T11:00:00.000Z', '1st of the month - 4 months')
assert.equal(func(5, 'month'), '2023-06-01T11:00:00.000Z', '1st of the month - 5 months')
assert.equal(func(6, 'month'), '2023-07-01T11:00:00.000Z', '1st of the month - 6 months')
assert.equal(func(7, 'month'), '2023-08-01T11:00:00.000Z', '1st of the month - 7 months')
assert.equal(func(8, 'month'), '2023-09-01T11:00:00.000Z', '1st of the month - 8 months')
assert.equal(func(9, 'month'), '2023-10-01T11:00:00.000Z', '1st of the month - 9 months')
assert.equal(func(10, 'month'), '2023-11-01T12:00:00.000Z', '1st of the month - 10 months')
assert.equal(func(11, 'month'), '2023-12-01T12:00:00.000Z', '1st of the month - 11 months')
assert.equal(func(12, 'month'), '2024-01-01T12:00:00.000Z', '1st of the month - 12 months')
clock = sinon.useFakeTimers({ now: new Date('2023-01-28T12:00:00.000Z') })
assert.equal(func(1, 'month'), '2023-02-28T12:00:00.000Z', '28th of the month - 1 month')
assert.equal(func(2, 'month'), '2023-03-28T11:00:00.000Z', '28th of the month - 2 months')
assert.equal(func(3, 'month'), '2023-04-28T11:00:00.000Z', '28th of the month - 3 months')
assert.equal(func(4, 'month'), '2023-05-28T11:00:00.000Z', '28th of the month - 4 months')
assert.equal(func(5, 'month'), '2023-06-28T11:00:00.000Z', '28th of the month - 5 months')
assert.equal(func(6, 'month'), '2023-07-28T11:00:00.000Z', '28th of the month - 6 months')
assert.equal(func(7, 'month'), '2023-08-28T11:00:00.000Z', '28th of the month - 7 months')
assert.equal(func(8, 'month'), '2023-09-28T11:00:00.000Z', '28th of the month - 8 months')
assert.equal(func(9, 'month'), '2023-10-28T11:00:00.000Z', '28th of the month - 9 months')
assert.equal(func(10, 'month'), '2023-11-28T12:00:00.000Z', '28th of the month - 10 months')
assert.equal(func(11, 'month'), '2023-12-28T12:00:00.000Z', '28th of the month - 11 months')
assert.equal(func(12, 'month'), '2024-01-28T12:00:00.000Z', '28th of the month - 12 months')
clock = sinon.useFakeTimers({ now: new Date('2023-01-29T12:00:00.000Z') })
assert.equal(func(1, 'month'), '2023-03-01T12:00:00.000Z', '29th of the month - 1 month')
assert.equal(func(2, 'month'), '2023-03-29T11:00:00.000Z', '29th of the month - 2 months')
assert.equal(func(3, 'month'), '2023-04-29T11:00:00.000Z', '29th of the month - 3 months')
assert.equal(func(4, 'month'), '2023-05-29T11:00:00.000Z', '29th of the month - 4 months')
assert.equal(func(5, 'month'), '2023-06-29T11:00:00.000Z', '29th of the month - 5 months')
assert.equal(func(6, 'month'), '2023-07-29T11:00:00.000Z', '29th of the month - 6 months')
assert.equal(func(7, 'month'), '2023-08-29T11:00:00.000Z', '29th of the month - 7 months')
assert.equal(func(8, 'month'), '2023-09-29T11:00:00.000Z', '29th of the month - 8 months')
assert.equal(func(9, 'month'), '2023-10-29T12:00:00.000Z', '29th of the month - 9 months')
assert.equal(func(10, 'month'), '2023-11-29T12:00:00.000Z', '29th of the month - 10 months')
assert.equal(func(11, 'month'), '2023-12-29T12:00:00.000Z', '29th of the month - 11 months')
assert.equal(func(12, 'month'), '2024-01-29T12:00:00.000Z', '29th of the month - 12 months')
clock = sinon.useFakeTimers({ now: new Date('2023-01-30T12:00:00.000Z') })
assert.equal(func(1, 'month'), '2023-03-02T12:00:00.000Z', '30th of the month - 1 month')
assert.equal(func(2, 'month'), '2023-03-30T11:00:00.000Z', '30th of the month - 2 months')
assert.equal(func(3, 'month'), '2023-04-30T11:00:00.000Z', '30th of the month - 3 months')
assert.equal(func(4, 'month'), '2023-05-30T11:00:00.000Z', '30th of the month - 4 months')
assert.equal(func(5, 'month'), '2023-06-30T11:00:00.000Z', '30th of the month - 5 months')
assert.equal(func(6, 'month'), '2023-07-30T11:00:00.000Z', '30th of the month - 6 months')
assert.equal(func(7, 'month'), '2023-08-30T11:00:00.000Z', '30th of the month - 7 months')
assert.equal(func(8, 'month'), '2023-09-30T11:00:00.000Z', '30th of the month - 8 months')
assert.equal(func(9, 'month'), '2023-10-30T12:00:00.000Z', '30th of the month - 9 months')
assert.equal(func(10, 'month'), '2023-11-30T12:00:00.000Z', '30th of the month - 10 months')
assert.equal(func(11, 'month'), '2023-12-30T12:00:00.000Z', '30th of the month - 11 months')
assert.equal(func(12, 'month'), '2024-01-30T12:00:00.000Z', '30th of the month - 12 months')
clock = sinon.useFakeTimers({ now: new Date('2023-01-31T12:00:00.000Z') })
assert.equal(func(1, 'month'), '2023-03-03T12:00:00.000Z', '31st of the month - 1 month')
assert.equal(func(2, 'month'), '2023-03-31T11:00:00.000Z', '31st of the month - 2 months')
assert.equal(func(3, 'month'), '2023-05-01T11:00:00.000Z', '31st of the month - 3 months')
assert.equal(func(4, 'month'), '2023-05-31T11:00:00.000Z', '31st of the month - 4 months')
assert.equal(func(5, 'month'), '2023-07-01T11:00:00.000Z', '31st of the month - 5 months')
assert.equal(func(6, 'month'), '2023-07-31T11:00:00.000Z', '31st of the month - 6 months')
assert.equal(func(7, 'month'), '2023-08-31T11:00:00.000Z', '31st of the month - 7 months')
assert.equal(func(8, 'month'), '2023-10-01T11:00:00.000Z', '31st of the month - 8 months')
assert.equal(func(9, 'month'), '2023-10-31T12:00:00.000Z', '31st of the month - 9 months')
assert.equal(func(10, 'month'), '2023-12-01T12:00:00.000Z', '31st of the month - 10 months')
assert.equal(func(11, 'month'), '2023-12-31T12:00:00.000Z', '31st of the month - 11 months')
assert.equal(func(12, 'month'), '2024-01-31T12:00:00.000Z', '31st of the month - 12 months')
clock.restore()
})