javascript-time-ago 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/javascript-time-ago.js +1 -1
- package/bundle/javascript-time-ago.js.map +1 -1
- package/bundle/javascript-time-ago.min.js +1 -1
- package/bundle/javascript-time-ago.min.js.map +1 -1
- package/commonjs/FullDateFormatter.test.js +11 -9
- package/commonjs/FullDateFormatter.test.js.map +1 -1
- package/commonjs/TimeAgo.test.js +237 -236
- package/commonjs/TimeAgo.test.js.map +1 -1
- package/commonjs/cache.test.js +8 -6
- package/commonjs/cache.test.js.map +1 -1
- package/commonjs/isStyleObject.test.js +21 -19
- package/commonjs/isStyleObject.test.js.map +1 -1
- package/commonjs/locale.test.js +16 -14
- package/commonjs/locale.test.js.map +1 -1
- package/commonjs/steps/approximate.test.js +26 -24
- package/commonjs/steps/approximate.test.js.map +1 -1
- package/commonjs/steps/getStep.test.js +20 -18
- package/commonjs/steps/getStep.test.js.map +1 -1
- package/commonjs/steps/getStepDenominator.test.js +9 -7
- package/commonjs/steps/getStepDenominator.test.js.map +1 -1
- package/commonjs/steps/getStepMinTime.test.js +9 -7
- package/commonjs/steps/getStepMinTime.test.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdate.test.js +56 -54
- package/commonjs/steps/getTimeToNextUpdate.test.js.map +1 -1
- package/commonjs/steps/getTimeToNextUpdateForUnit.test.js +20 -18
- package/commonjs/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
- package/commonjs/steps/helpers.test.js +6 -4
- package/commonjs/steps/helpers.test.js.map +1 -1
- package/commonjs/steps/renameLegacyProperties.test.js +12 -10
- package/commonjs/steps/renameLegacyProperties.test.js.map +1 -1
- package/commonjs/steps/round.test.js +27 -25
- package/commonjs/steps/round.test.js.map +1 -1
- package/commonjs/style/approximateTime.test.js +6 -5
- package/commonjs/style/approximateTime.test.js.map +1 -1
- package/commonjs/style/mini.test.js +62 -60
- package/commonjs/style/mini.test.js.map +1 -1
- package/commonjs/style/miniMinute.test.js +27 -25
- package/commonjs/style/miniMinute.test.js.map +1 -1
- package/commonjs/style/miniMinuteNow.test.js +27 -25
- package/commonjs/style/miniMinuteNow.test.js.map +1 -1
- package/commonjs/style/miniNow.test.js +27 -25
- package/commonjs/style/miniNow.test.js.map +1 -1
- package/commonjs/style/renameLegacyProperties.test.js +9 -7
- package/commonjs/style/renameLegacyProperties.test.js.map +1 -1
- package/commonjs/style/round.test.js +81 -79
- package/commonjs/style/round.test.js.map +1 -1
- package/commonjs/style/roundMinute.test.js +50 -48
- package/commonjs/style/roundMinute.test.js.map +1 -1
- package/commonjs/style/twitter.test.js +86 -84
- package/commonjs/style/twitter.test.js.map +1 -1
- package/commonjs/style/twitterFirstMinute.test.js +33 -31
- package/commonjs/style/twitterFirstMinute.test.js.map +1 -1
- package/commonjs/style/twitterMinute.test.js +32 -30
- package/commonjs/style/twitterMinute.test.js.map +1 -1
- package/commonjs/style/twitterMinuteNow.test.js +32 -30
- package/commonjs/style/twitterMinuteNow.test.js.map +1 -1
- package/commonjs/style/twitterNow.test.js +34 -32
- package/commonjs/style/twitterNow.test.js.map +1 -1
- package/load-all-locales/index.cjs +15 -0
- package/load-all-locales/index.cjs.js +15 -0
- package/load-all-locales/index.js +30 -0
- package/locale/ak.json +8 -26
- package/locale/ak.json.js +8 -26
- package/locale/am.json +3 -3
- package/locale/am.json.js +3 -3
- package/locale/ba/package.json +16 -0
- package/locale/ba.json +159 -0
- package/locale/ba.json.d.ts +4 -0
- package/locale/ba.json.js +159 -0
- package/locale/be-tarask.json +4 -4
- package/locale/be-tarask.json.js +4 -4
- package/locale/be.json +4 -4
- package/locale/be.json.js +4 -4
- package/locale/bn.json +6 -6
- package/locale/bn.json.js +6 -6
- package/locale/bs.json +36 -30
- package/locale/bs.json.js +36 -30
- package/locale/bua/package.json +16 -0
- package/locale/bua.json +159 -0
- package/locale/bua.json.d.ts +4 -0
- package/locale/bua.json.js +159 -0
- package/locale/cv.json +134 -82
- package/locale/cv.json.js +134 -82
- package/locale/en-EE/package.json +16 -0
- package/locale/en-EE.json +219 -0
- package/locale/en-EE.json.d.ts +4 -0
- package/locale/en-EE.json.js +219 -0
- package/locale/en-GE/package.json +16 -0
- package/locale/en-GE.json +219 -0
- package/locale/en-GE.json.d.ts +4 -0
- package/locale/en-GE.json.js +219 -0
- package/locale/en-LT/package.json +16 -0
- package/locale/en-LT.json +219 -0
- package/locale/en-LT.json.d.ts +4 -0
- package/locale/en-LT.json.js +219 -0
- package/locale/en-LV/package.json +16 -0
- package/locale/en-LV.json +219 -0
- package/locale/en-LV.json.d.ts +4 -0
- package/locale/en-LV.json.js +219 -0
- package/locale/en-UA/package.json +16 -0
- package/locale/en-UA.json +219 -0
- package/locale/en-UA.json.d.ts +4 -0
- package/locale/en-UA.json.js +219 -0
- package/locale/es-MX.json +2 -8
- package/locale/es-MX.json.js +2 -8
- package/locale/fr-CA.json +4 -4
- package/locale/fr-CA.json.js +4 -4
- package/locale/fr.json +4 -4
- package/locale/fr.json.js +4 -4
- package/locale/he.json +74 -86
- package/locale/he.json.js +74 -86
- package/locale/ht.json +4 -4
- package/locale/ht.json.js +4 -4
- package/locale/ie.json +15 -9
- package/locale/ie.json.js +15 -9
- package/locale/kk-Arab/package.json +16 -0
- package/locale/kk-Arab.json +159 -0
- package/locale/kk-Arab.json.d.ts +4 -0
- package/locale/kk-Arab.json.js +159 -0
- package/locale/kok-Latn.json +138 -39
- package/locale/kok-Latn.json.js +138 -39
- package/locale/kok.json +169 -64
- package/locale/kok.json.js +169 -64
- package/locale/ku.json +166 -73
- package/locale/ku.json.js +166 -73
- package/locale/mk.json +20 -20
- package/locale/mk.json.js +20 -20
- package/locale/nso/package.json +16 -0
- package/locale/nso.json +159 -0
- package/locale/nso.json.d.ts +4 -0
- package/locale/nso.json.js +159 -0
- package/locale/rm.json +151 -85
- package/locale/rm.json.js +151 -85
- package/locale/ro.json +4 -2
- package/locale/ro.json.js +4 -2
- package/locale/rw/package.json +16 -0
- package/locale/rw.json +159 -0
- package/locale/rw.json.d.ts +4 -0
- package/locale/rw.json.js +159 -0
- package/locale/scn/package.json +16 -0
- package/locale/scn.json +249 -0
- package/locale/scn.json.d.ts +4 -0
- package/locale/scn.json.js +249 -0
- package/locale/sd-Deva/package.json +16 -0
- package/locale/sd-Deva.json +159 -0
- package/locale/sd-Deva.json.d.ts +4 -0
- package/locale/sd-Deva.json.js +159 -0
- package/locale/sd.json +77 -20
- package/locale/sd.json.js +77 -20
- package/locale/shn/package.json +16 -0
- package/locale/shn.json +159 -0
- package/locale/shn.json.d.ts +4 -0
- package/locale/shn.json.js +159 -0
- package/locale/sv.json +3 -3
- package/locale/sv.json.js +3 -3
- package/locale/syr.json +27 -27
- package/locale/syr.json.js +27 -27
- package/locale/ta.json +15 -9
- package/locale/ta.json.js +15 -9
- package/locale/tn.json +27 -27
- package/locale/tn.json.js +27 -27
- package/locale/tok/package.json +16 -0
- package/locale/tok.json +159 -0
- package/locale/tok.json.d.ts +4 -0
- package/locale/tok.json.js +159 -0
- package/locale/tyv/package.json +16 -0
- package/locale/tyv.json +159 -0
- package/locale/tyv.json.d.ts +4 -0
- package/locale/tyv.json.js +159 -0
- package/locale/xh.json +18 -18
- package/locale/xh.json.js +18 -18
- package/modules/FullDateFormatter.test.js +2 -0
- package/modules/FullDateFormatter.test.js.map +1 -1
- package/modules/TimeAgo.test.js +190 -189
- package/modules/TimeAgo.test.js.map +1 -1
- package/modules/cache.test.js +2 -0
- package/modules/cache.test.js.map +1 -1
- package/modules/isStyleObject.test.js +19 -17
- package/modules/isStyleObject.test.js.map +1 -1
- package/modules/locale.test.js +12 -10
- package/modules/locale.test.js.map +1 -1
- package/modules/steps/approximate.test.js +2 -0
- package/modules/steps/approximate.test.js.map +1 -1
- package/modules/steps/getStep.test.js +7 -5
- package/modules/steps/getStep.test.js.map +1 -1
- package/modules/steps/getStepDenominator.test.js +6 -4
- package/modules/steps/getStepDenominator.test.js.map +1 -1
- package/modules/steps/getStepMinTime.test.js +6 -4
- package/modules/steps/getStepMinTime.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdate.test.js +36 -34
- package/modules/steps/getTimeToNextUpdate.test.js.map +1 -1
- package/modules/steps/getTimeToNextUpdateForUnit.test.js +12 -10
- package/modules/steps/getTimeToNextUpdateForUnit.test.js.map +1 -1
- package/modules/steps/helpers.test.js +4 -2
- package/modules/steps/helpers.test.js.map +1 -1
- package/modules/steps/renameLegacyProperties.test.js +8 -6
- package/modules/steps/renameLegacyProperties.test.js.map +1 -1
- package/modules/steps/round.test.js +2 -0
- package/modules/steps/round.test.js.map +1 -1
- package/modules/style/approximateTime.test.js +3 -2
- package/modules/style/approximateTime.test.js.map +1 -1
- package/modules/style/mini.test.js +58 -56
- package/modules/style/mini.test.js.map +1 -1
- package/modules/style/miniMinute.test.js +25 -23
- package/modules/style/miniMinute.test.js.map +1 -1
- package/modules/style/miniMinuteNow.test.js +25 -23
- package/modules/style/miniMinuteNow.test.js.map +1 -1
- package/modules/style/miniNow.test.js +25 -23
- package/modules/style/miniNow.test.js.map +1 -1
- package/modules/style/renameLegacyProperties.test.js +6 -4
- package/modules/style/renameLegacyProperties.test.js.map +1 -1
- package/modules/style/round.test.js +76 -74
- package/modules/style/round.test.js.map +1 -1
- package/modules/style/roundMinute.test.js +47 -45
- package/modules/style/roundMinute.test.js.map +1 -1
- package/modules/style/twitter.test.js +72 -70
- package/modules/style/twitter.test.js.map +1 -1
- package/modules/style/twitterFirstMinute.test.js +29 -27
- package/modules/style/twitterFirstMinute.test.js.map +1 -1
- package/modules/style/twitterMinute.test.js +29 -27
- package/modules/style/twitterMinute.test.js.map +1 -1
- package/modules/style/twitterMinuteNow.test.js +29 -27
- package/modules/style/twitterMinuteNow.test.js.map +1 -1
- package/modules/style/twitterNow.test.js +31 -29
- package/modules/style/twitterNow.test.js.map +1 -1
- package/package.json +126 -5
package/modules/TimeAgo.test.js
CHANGED
|
@@ -4,8 +4,9 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
4
4
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) { n[e] = r[e]; } return n; }
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) { ; } } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import { describe, it } from 'mocha';
|
|
8
|
+
import { expect } from 'chai';
|
|
7
9
|
import TimeAgo from './TimeAgo.js';
|
|
8
|
-
import { getLocaleData } from './LocaleDataStore.js';
|
|
9
10
|
|
|
10
11
|
// Load locale specific relative date/time messages
|
|
11
12
|
import english from '../locale/en.json' assert { type: 'json' };
|
|
@@ -15,19 +16,19 @@ TimeAgo.setDefaultLocale('en');
|
|
|
15
16
|
describe("javascript-time-ago", function () {
|
|
16
17
|
it('should default to "round-minute" style', function () {
|
|
17
18
|
var timeAgo = new TimeAgo('en');
|
|
18
|
-
timeAgo.format(Date.now()).
|
|
19
|
-
timeAgo.format(Date.now() + 20 * 1000).
|
|
20
|
-
timeAgo.format(Date.now() + 1 * 60 * 1000).
|
|
21
|
-
timeAgo.format(Date.now() + 4 * 60 * 1000).
|
|
19
|
+
expect(timeAgo.format(Date.now())).to.equal('just now');
|
|
20
|
+
expect(timeAgo.format(Date.now() + 20 * 1000)).to.equal('in a moment');
|
|
21
|
+
expect(timeAgo.format(Date.now() + 1 * 60 * 1000)).to.equal('in 1 minute');
|
|
22
|
+
expect(timeAgo.format(Date.now() + 4 * 60 * 1000)).to.equal('in 4 minutes');
|
|
22
23
|
});
|
|
23
24
|
it('should tell `options` argument from `style` argument', function () {
|
|
24
25
|
var timeAgo = new TimeAgo('en');
|
|
25
|
-
timeAgo.format(Date.now(), 'mini-now').
|
|
26
|
-
timeAgo.format(0, {
|
|
26
|
+
expect(timeAgo.format(Date.now(), 'mini-now')).to.equal('now');
|
|
27
|
+
expect(timeAgo.format(0, {
|
|
27
28
|
future: true,
|
|
28
29
|
now: 0
|
|
29
|
-
}).
|
|
30
|
-
timeAgo.format(0, {
|
|
30
|
+
})).to.equal('in a moment');
|
|
31
|
+
expect(timeAgo.format(0, {
|
|
31
32
|
labels: 'mini',
|
|
32
33
|
steps: [{
|
|
33
34
|
formatAs: 'now'
|
|
@@ -37,8 +38,8 @@ describe("javascript-time-ago", function () {
|
|
|
37
38
|
}, {
|
|
38
39
|
future: true,
|
|
39
40
|
now: 0
|
|
40
|
-
}).
|
|
41
|
-
timeAgo.format(0, {
|
|
41
|
+
})).to.equal('now');
|
|
42
|
+
expect(timeAgo.format(0, {
|
|
42
43
|
labels: ['mini'],
|
|
43
44
|
steps: [{
|
|
44
45
|
formatAs: 'now'
|
|
@@ -48,49 +49,49 @@ describe("javascript-time-ago", function () {
|
|
|
48
49
|
}, {
|
|
49
50
|
future: true,
|
|
50
51
|
now: 0
|
|
51
|
-
}).
|
|
52
|
+
})).to.equal('now');
|
|
52
53
|
// `flavour` is a legacy name of `labels` property.
|
|
53
|
-
timeAgo.format(0, {
|
|
54
|
+
expect(timeAgo.format(0, {
|
|
54
55
|
flavour: 'mini'
|
|
55
56
|
}, {
|
|
56
57
|
future: true,
|
|
57
58
|
now: 0
|
|
58
|
-
}).
|
|
59
|
-
timeAgo.format(0, {
|
|
59
|
+
})).to.equal('now');
|
|
60
|
+
expect(timeAgo.format(0, {
|
|
60
61
|
flavour: ['mini']
|
|
61
62
|
}, {
|
|
62
63
|
future: true,
|
|
63
64
|
now: 0
|
|
64
|
-
}).
|
|
65
|
-
timeAgo.format(0, {
|
|
65
|
+
})).to.equal('now');
|
|
66
|
+
expect(timeAgo.format(0, {
|
|
66
67
|
steps: [{
|
|
67
68
|
formatAs: 'minute'
|
|
68
69
|
}]
|
|
69
70
|
}, {
|
|
70
71
|
future: true,
|
|
71
72
|
now: 0
|
|
72
|
-
}).
|
|
73
|
+
})).to.equal('in 0 minutes');
|
|
73
74
|
// `gradation` is a legacy name of `steps` property.
|
|
74
|
-
timeAgo.format(0, {
|
|
75
|
+
expect(timeAgo.format(0, {
|
|
75
76
|
gradation: [{
|
|
76
77
|
formatAs: 'minute'
|
|
77
78
|
}]
|
|
78
79
|
}, {
|
|
79
80
|
future: true,
|
|
80
81
|
now: 0
|
|
81
|
-
}).
|
|
82
|
+
})).to.equal('in 0 minutes');
|
|
82
83
|
});
|
|
83
84
|
it('should try various label types until an appropriate one is found', function () {
|
|
84
85
|
var timeAgo = new TimeAgo('en');
|
|
85
|
-
timeAgo.format(Date.now(), {
|
|
86
|
+
expect(timeAgo.format(Date.now(), {
|
|
86
87
|
labels: ['exotic', 'short']
|
|
87
|
-
}).
|
|
88
|
+
})).to.equal('just now');
|
|
88
89
|
});
|
|
89
90
|
it('should support the legacy name "flavour" of "labels"', function () {
|
|
90
91
|
var timeAgo = new TimeAgo('en');
|
|
91
|
-
timeAgo.format(Date.now(), {
|
|
92
|
+
expect(timeAgo.format(Date.now(), {
|
|
92
93
|
labels: ['exotic', 'short']
|
|
93
|
-
}).
|
|
94
|
+
})).to.equal('just now');
|
|
94
95
|
});
|
|
95
96
|
it('should fallback to "second.current" for "now" when "now" is not defined', function () {
|
|
96
97
|
var timeAgo = new TimeAgo('en');
|
|
@@ -98,28 +99,28 @@ describe("javascript-time-ago", function () {
|
|
|
98
99
|
delete english.now;
|
|
99
100
|
TimeAgo.addLocale(english);
|
|
100
101
|
english.now = undefined;
|
|
101
|
-
timeAgo.format(Date.now(), {
|
|
102
|
+
expect(timeAgo.format(Date.now(), {
|
|
102
103
|
labels: 'long'
|
|
103
|
-
}).
|
|
104
|
+
})).to.equal('now');
|
|
104
105
|
english.now = englishNow;
|
|
105
|
-
timeAgo.format(Date.now(), {
|
|
106
|
+
expect(timeAgo.format(Date.now(), {
|
|
106
107
|
labels: 'long'
|
|
107
|
-
}).
|
|
108
|
+
})).to.equal('just now');
|
|
108
109
|
});
|
|
109
110
|
it('should not use Intl.NumberFormat if it is not available', function () {
|
|
110
111
|
var NumberFormat = Intl.NumberFormat;
|
|
111
112
|
delete Intl.NumberFormat;
|
|
112
113
|
var timeAgo = new TimeAgo('en');
|
|
113
|
-
timeAgo.format(Date.now() + 60 * 1000, {
|
|
114
|
+
expect(timeAgo.format(Date.now() + 60 * 1000, {
|
|
114
115
|
labels: 'long-time'
|
|
115
|
-
}).
|
|
116
|
+
})).to.equal('1 minute');
|
|
116
117
|
Intl.NumberFormat = NumberFormat;
|
|
117
118
|
});
|
|
118
119
|
it('should work when "past"/"future" messages are same for all quantifiers', function () {
|
|
119
120
|
var timeAgo = new TimeAgo('en');
|
|
120
|
-
timeAgo.format(Date.now() + 365 * 24 * 60 * 60 * 1000, {
|
|
121
|
+
expect(timeAgo.format(Date.now() + 365 * 24 * 60 * 60 * 1000, {
|
|
121
122
|
labels: 'short'
|
|
122
|
-
}).
|
|
123
|
+
})).to.equal('in 1 yr.');
|
|
123
124
|
});
|
|
124
125
|
it('should work when "now" is a string (does not differentiate between "past" and "future")', function () {
|
|
125
126
|
var timeAgo = new TimeAgo('en');
|
|
@@ -128,13 +129,13 @@ describe("javascript-time-ago", function () {
|
|
|
128
129
|
now: 'now'
|
|
129
130
|
};
|
|
130
131
|
TimeAgo.addLocale(english);
|
|
131
|
-
timeAgo.format(Date.now(), {
|
|
132
|
+
expect(timeAgo.format(Date.now(), {
|
|
132
133
|
labels: 'long'
|
|
133
|
-
}).
|
|
134
|
+
})).to.equal('now');
|
|
134
135
|
english.now = englishNow;
|
|
135
|
-
timeAgo.format(Date.now(), {
|
|
136
|
+
expect(timeAgo.format(Date.now(), {
|
|
136
137
|
labels: 'long'
|
|
137
|
-
}).
|
|
138
|
+
})).to.equal('just now');
|
|
138
139
|
});
|
|
139
140
|
it('should work when a unit has formatting rules for "past" and "future" which are strings (style: not "long", not "short", not "narrow")', function () {
|
|
140
141
|
var timeAgo = new TimeAgo('en');
|
|
@@ -145,70 +146,70 @@ describe("javascript-time-ago", function () {
|
|
|
145
146
|
};
|
|
146
147
|
TimeAgo.addLocale(english);
|
|
147
148
|
// Past.
|
|
148
|
-
timeAgo.format(Date.now() - 60 * 1000, {
|
|
149
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, {
|
|
149
150
|
labels: 'long-time'
|
|
150
|
-
}).
|
|
151
|
+
})).to.equal('1 minute(s) ago');
|
|
151
152
|
// Future (covers an "else" branch).
|
|
152
|
-
timeAgo.format(Date.now() + 60 * 1000, {
|
|
153
|
+
expect(timeAgo.format(Date.now() + 60 * 1000, {
|
|
153
154
|
labels: 'long-time'
|
|
154
|
-
}).
|
|
155
|
+
})).to.equal('in 1 minute(s)');
|
|
155
156
|
// Undo.
|
|
156
157
|
english['long-time'].minute = englishLongTimeMinute;
|
|
157
|
-
timeAgo.format(Date.now() - 60 * 1000, {
|
|
158
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, {
|
|
158
159
|
labels: 'long-time'
|
|
159
|
-
}).
|
|
160
|
+
})).to.equal('1 minute');
|
|
160
161
|
});
|
|
161
162
|
it("should format \"now\" for \"past\" time", function () {
|
|
162
163
|
var timeAgo = new TimeAgo('en');
|
|
163
|
-
timeAgo.format(Date.now() + 10, {
|
|
164
|
+
expect(timeAgo.format(Date.now() + 10, {
|
|
164
165
|
labels: ['long']
|
|
165
|
-
}).
|
|
166
|
+
})).to.equal('in a moment');
|
|
166
167
|
});
|
|
167
168
|
it('should accept a string style name argument', function () {
|
|
168
169
|
var timeAgo = new TimeAgo('en');
|
|
169
170
|
// "mini".
|
|
170
|
-
timeAgo.format(Date.now() - 0 * 1000, 'mini').
|
|
171
|
-
timeAgo.format(Date.now() - 1 * 1000, 'mini').
|
|
171
|
+
expect(timeAgo.format(Date.now() - 0 * 1000, 'mini')).to.equal('0s');
|
|
172
|
+
expect(timeAgo.format(Date.now() - 1 * 1000, 'mini')).to.equal('1s');
|
|
172
173
|
// "mini-now".
|
|
173
|
-
timeAgo.format(Date.now() - 0 * 1000, 'mini-now').
|
|
174
|
-
timeAgo.format(Date.now() - 1 * 1000, 'mini-now').
|
|
174
|
+
expect(timeAgo.format(Date.now() - 0 * 1000, 'mini-now')).to.equal('now');
|
|
175
|
+
expect(timeAgo.format(Date.now() - 1 * 1000, 'mini-now')).to.equal('1s');
|
|
175
176
|
// "mini-minute-now".
|
|
176
|
-
timeAgo.format(Date.now() - 29 * 1000, 'mini-minute-now').
|
|
177
|
-
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute-now').
|
|
177
|
+
expect(timeAgo.format(Date.now() - 29 * 1000, 'mini-minute-now')).to.equal('now');
|
|
178
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, 'mini-minute-now')).to.equal('1m');
|
|
178
179
|
// "mini-minute".
|
|
179
|
-
timeAgo.format(Date.now() - 29 * 1000, 'mini-minute').
|
|
180
|
-
timeAgo.format(Date.now() - 60 * 1000, 'mini-minute').
|
|
180
|
+
expect(timeAgo.format(Date.now() - 29 * 1000, 'mini-minute')).to.equal('0m');
|
|
181
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, 'mini-minute')).to.equal('1m');
|
|
181
182
|
// "twitter".
|
|
182
|
-
timeAgo.format(Date.now() - 0 * 1000, 'twitter').
|
|
183
|
-
timeAgo.format(Date.now() - 1 * 1000, 'twitter').
|
|
183
|
+
expect(timeAgo.format(Date.now() - 0 * 1000, 'twitter')).to.equal('0s');
|
|
184
|
+
expect(timeAgo.format(Date.now() - 1 * 1000, 'twitter')).to.equal('1s');
|
|
184
185
|
// "twitter-now".
|
|
185
|
-
timeAgo.format(Date.now() - 0 * 1000, 'twitter-now').
|
|
186
|
-
timeAgo.format(Date.now() - 1 * 1000, 'twitter-now').
|
|
186
|
+
expect(timeAgo.format(Date.now() - 0 * 1000, 'twitter-now')).to.equal('now');
|
|
187
|
+
expect(timeAgo.format(Date.now() - 1 * 1000, 'twitter-now')).to.equal('1s');
|
|
187
188
|
// "twitter-minute-now".
|
|
188
|
-
timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute-now').
|
|
189
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute-now').
|
|
189
|
+
expect(timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute-now')).to.equal('now');
|
|
190
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute-now')).to.equal('1m');
|
|
190
191
|
// "twitter-minute".
|
|
191
|
-
timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute').
|
|
192
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute').
|
|
192
|
+
expect(timeAgo.format(Date.now() - 29 * 1000, 'twitter-minute')).to.equal('0m');
|
|
193
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, 'twitter-minute')).to.equal('1m');
|
|
193
194
|
// "twitter-first-minute".
|
|
194
|
-
timeAgo.format(Date.now() - 29 * 1000, 'twitter-first-minute').
|
|
195
|
-
timeAgo.format(Date.now() - 60 * 1000, 'twitter-first-minute').
|
|
195
|
+
expect(timeAgo.format(Date.now() - 29 * 1000, 'twitter-first-minute')).to.equal('');
|
|
196
|
+
expect(timeAgo.format(Date.now() - 60 * 1000, 'twitter-first-minute')).to.equal('1m');
|
|
196
197
|
// "approximate".
|
|
197
|
-
timeAgo.format(Date.now() - 45 * 1000, 'approximate').
|
|
198
|
+
expect(timeAgo.format(Date.now() - 45 * 1000, 'approximate')).to.equal('just now');
|
|
198
199
|
// "convenient" style was renamed to "approximate".
|
|
199
|
-
timeAgo.format(Date.now() - 45 * 1000, 'convenient').
|
|
200
|
-
timeAgo.format(Date.now() - 45 * 1000, 'round').
|
|
200
|
+
expect(timeAgo.format(Date.now() - 45 * 1000, 'convenient')).to.equal('just now');
|
|
201
|
+
expect(timeAgo.format(Date.now() - 45 * 1000, 'round')).to.equal('45 seconds ago');
|
|
201
202
|
// "default" style was renamed to "round".
|
|
202
|
-
timeAgo.format(Date.now() - 45 * 1000, 'default').
|
|
203
|
-
timeAgo.format(Date.now() - 29 * 1000, 'round-minute').
|
|
203
|
+
expect(timeAgo.format(Date.now() - 45 * 1000, 'default')).to.equal('45 seconds ago');
|
|
204
|
+
expect(timeAgo.format(Date.now() - 29 * 1000, 'round-minute')).to.equal('just now');
|
|
204
205
|
// "time" style was renamed to "approximate-time".
|
|
205
|
-
timeAgo.format(Date.now() - 2 * 60 * 1000, 'time').
|
|
206
|
-
timeAgo.format(Date.now() - 2 * 60 * 1000, 'approximate-time').
|
|
207
|
-
timeAgo.format(Date.now(), 'exotic').
|
|
206
|
+
expect(timeAgo.format(Date.now() - 2 * 60 * 1000, 'time')).to.equal('2 minutes');
|
|
207
|
+
expect(timeAgo.format(Date.now() - 2 * 60 * 1000, 'approximate-time')).to.equal('2 minutes');
|
|
208
|
+
expect(timeAgo.format(Date.now(), 'exotic')).to.equal('just now');
|
|
208
209
|
});
|
|
209
210
|
it('should accept empty constructor parameters', function () {
|
|
210
211
|
var timeAgo = new TimeAgo();
|
|
211
|
-
timeAgo.format(new Date()).
|
|
212
|
+
expect(timeAgo.format(new Date())).to.equal('just now');
|
|
212
213
|
});
|
|
213
214
|
it('should accept "mocked" Dates when testing', function () {
|
|
214
215
|
var timeAgo = new TimeAgo('en');
|
|
@@ -217,24 +218,24 @@ describe("javascript-time-ago", function () {
|
|
|
217
218
|
return Date.now();
|
|
218
219
|
}
|
|
219
220
|
};
|
|
220
|
-
timeAgo.format(mockedDate).
|
|
221
|
+
expect(timeAgo.format(mockedDate)).to.equal('just now');
|
|
221
222
|
});
|
|
222
223
|
it('should not accept anything but Dates and timestamps', function () {
|
|
223
224
|
var timeAgo = new TimeAgo('en');
|
|
224
225
|
var thrower = function thrower() {
|
|
225
226
|
return timeAgo.format('Jan 14, 2017');
|
|
226
227
|
};
|
|
227
|
-
thrower.
|
|
228
|
+
expect(thrower).to["throw"]('Unsupported relative time formatter input: string, Jan 14, 2017');
|
|
228
229
|
});
|
|
229
230
|
it('should return an empty string if the specified units are not available in locale data', function () {
|
|
230
231
|
var timeAgo = new TimeAgo('en');
|
|
231
|
-
timeAgo.format(Date.now(), {
|
|
232
|
+
expect(timeAgo.format(Date.now(), {
|
|
232
233
|
units: ['femtosecond']
|
|
233
|
-
}).
|
|
234
|
+
})).to.equal('');
|
|
234
235
|
});
|
|
235
236
|
it('should format for a style with "custom" function', function () {
|
|
236
237
|
var timeAgo = new TimeAgo('en');
|
|
237
|
-
timeAgo.format(Date.now(), {
|
|
238
|
+
expect(timeAgo.format(Date.now(), {
|
|
238
239
|
// `custom` returns a string
|
|
239
240
|
custom: function custom(_ref) {
|
|
240
241
|
var now = _ref.now,
|
|
@@ -243,8 +244,8 @@ describe("javascript-time-ago", function () {
|
|
|
243
244
|
locale = _ref.locale;
|
|
244
245
|
return locale;
|
|
245
246
|
}
|
|
246
|
-
}).
|
|
247
|
-
timeAgo.format(Date.now(), {
|
|
247
|
+
})).to.equal('en');
|
|
248
|
+
expect(timeAgo.format(Date.now(), {
|
|
248
249
|
// `custom` returns `undefined`
|
|
249
250
|
custom: function custom(_ref2) {
|
|
250
251
|
var now = _ref2.now,
|
|
@@ -253,7 +254,7 @@ describe("javascript-time-ago", function () {
|
|
|
253
254
|
locale = _ref2.locale;
|
|
254
255
|
return;
|
|
255
256
|
}
|
|
256
|
-
}).
|
|
257
|
+
})).to.equal('just now');
|
|
257
258
|
});
|
|
258
259
|
it('should throw an error when formating for a style with "custom" function and `getTimeToNextUpdate: true` parameter is passed', function () {
|
|
259
260
|
var timeAgo = new TimeAgo('en');
|
|
@@ -273,15 +274,15 @@ describe("javascript-time-ago", function () {
|
|
|
273
274
|
}).to["throw"]('not supported');
|
|
274
275
|
});
|
|
275
276
|
it('should format future dates', function () {
|
|
276
|
-
new TimeAgo('en').format(Date.now() + 60 * 60 * 1000).
|
|
277
|
-
new TimeAgo('ru').format(Date.now() + 60 * 1000).
|
|
277
|
+
expect(new TimeAgo('en').format(Date.now() + 60 * 60 * 1000)).to.equal('in 1 hour');
|
|
278
|
+
expect(new TimeAgo('ru').format(Date.now() + 60 * 1000)).to.equal('через 1 минуту');
|
|
278
279
|
});
|
|
279
280
|
it('should accept "future" option', function () {
|
|
280
281
|
// "now" unit.
|
|
281
|
-
new TimeAgo('en').format(Date.now()).
|
|
282
|
-
new TimeAgo('en').format(Date.now(), 'approximate', {
|
|
282
|
+
expect(new TimeAgo('en').format(Date.now())).to.equal('just now');
|
|
283
|
+
expect(new TimeAgo('en').format(Date.now(), 'approximate', {
|
|
283
284
|
future: true
|
|
284
|
-
}).
|
|
285
|
+
})).to.equal('in a moment');
|
|
285
286
|
|
|
286
287
|
// Non-"now" unit, "long" style.
|
|
287
288
|
// const style = {
|
|
@@ -291,8 +292,8 @@ describe("javascript-time-ago", function () {
|
|
|
291
292
|
// }],
|
|
292
293
|
// labels: 'long'
|
|
293
294
|
// }
|
|
294
|
-
// new TimeAgo('en').format(Date.now(), style).
|
|
295
|
-
// new TimeAgo('en').format(Date.now(), style, { future: true }).
|
|
295
|
+
// expect(new TimeAgo('en').format(Date.now(), style)).to.equal('0 seconds ago')
|
|
296
|
+
// expect(new TimeAgo('en').format(Date.now(), style, { future: true })).to.equal('in 0 seconds')
|
|
296
297
|
|
|
297
298
|
// Non-"now" unit, "mini" style.
|
|
298
299
|
var style2 = {
|
|
@@ -301,10 +302,10 @@ describe("javascript-time-ago", function () {
|
|
|
301
302
|
}],
|
|
302
303
|
labels: 'mini'
|
|
303
304
|
};
|
|
304
|
-
new TimeAgo('ru').format(Date.now() - 5 * 365 * 24 * 60 * 60 * 1000, style2).
|
|
305
|
-
new TimeAgo('ru').format(Date.now() - 5 * 365 * 24 * 60 * 60 * 1000, style2, {
|
|
305
|
+
expect(new TimeAgo('ru').format(Date.now() - 5 * 365 * 24 * 60 * 60 * 1000, style2)).to.equal('5 л');
|
|
306
|
+
expect(new TimeAgo('ru').format(Date.now() - 5 * 365 * 24 * 60 * 60 * 1000, style2, {
|
|
306
307
|
future: true
|
|
307
|
-
}).
|
|
308
|
+
})).to.equal('5 л');
|
|
308
309
|
});
|
|
309
310
|
it('should support the legacy properties: "gradation", "flavour", "factor", "unit", "\'tiny\'" labels style', function () {
|
|
310
311
|
// Non-"now" unit, "tiny" style.
|
|
@@ -315,18 +316,18 @@ describe("javascript-time-ago", function () {
|
|
|
315
316
|
}],
|
|
316
317
|
flavour: 'tiny'
|
|
317
318
|
};
|
|
318
|
-
new TimeAgo('ru').format(Date.now() - 10 * 1000, style).
|
|
319
|
-
new TimeAgo('ru').format(Date.now() - 10 * 1000, style, {
|
|
319
|
+
expect(new TimeAgo('ru').format(Date.now() - 10 * 1000, style)).to.equal('2 г');
|
|
320
|
+
expect(new TimeAgo('ru').format(Date.now() - 10 * 1000, style, {
|
|
320
321
|
future: true
|
|
321
|
-
}).
|
|
322
|
+
})).to.equal('2 г');
|
|
322
323
|
});
|
|
323
324
|
it('should have generated missing quantifier functions for locales that do not have it in CLDR data', function () {
|
|
324
|
-
new TimeAgo('ccp').format(Date.now() + 60 * 1000).
|
|
325
|
+
expect(new TimeAgo('ccp').format(Date.now() + 60 * 1000)).to.include(' 𑄟𑄨𑄚𑄨𑄘𑄬');
|
|
325
326
|
});
|
|
326
327
|
it('should throw for non-existing locales', function () {
|
|
327
|
-
(function () {
|
|
328
|
+
expect(function () {
|
|
328
329
|
return TimeAgo.addLocale();
|
|
329
|
-
}).
|
|
330
|
+
}).to["throw"]('No locale data passed');
|
|
330
331
|
});
|
|
331
332
|
it('should choose "future" variant of a label for `0` if "future: true" option is passed', function () {
|
|
332
333
|
TimeAgo.addLocale(english);
|
|
@@ -335,14 +336,14 @@ describe("javascript-time-ago", function () {
|
|
|
335
336
|
past: '{0} seconds ago',
|
|
336
337
|
future: 'in {0} seconds'
|
|
337
338
|
};
|
|
338
|
-
new TimeAgo('en').format(Date.now(), {
|
|
339
|
+
expect(new TimeAgo('en').format(Date.now(), {
|
|
339
340
|
steps: [{
|
|
340
341
|
unit: 'second'
|
|
341
342
|
}],
|
|
342
343
|
// Uses "mini" labels so that it doesn't use `Intl.RelativeTimeFormat`.
|
|
343
344
|
labels: 'mini'
|
|
344
|
-
}).
|
|
345
|
-
new TimeAgo('en').format(Date.now(), {
|
|
345
|
+
})).to.equal('0 seconds ago');
|
|
346
|
+
expect(new TimeAgo('en').format(Date.now(), {
|
|
346
347
|
steps: [{
|
|
347
348
|
unit: 'second'
|
|
348
349
|
}],
|
|
@@ -350,7 +351,7 @@ describe("javascript-time-ago", function () {
|
|
|
350
351
|
labels: 'mini'
|
|
351
352
|
}, {
|
|
352
353
|
future: true
|
|
353
|
-
}).
|
|
354
|
+
})).to.equal('in 0 seconds');
|
|
354
355
|
english['mini'].second = secondLabels;
|
|
355
356
|
});
|
|
356
357
|
it('should refresh the label when `refresh` parameter is passed', function () {
|
|
@@ -384,151 +385,151 @@ describe("javascript-time-ago", function () {
|
|
|
384
385
|
it('should get time to next update (capped)', function () {
|
|
385
386
|
var timeAgo = new TimeAgo('en');
|
|
386
387
|
// in 1 second -> in 0 seconds.
|
|
387
|
-
timeAgo.format(0.5 * 365 * 24 * 60 * 60 * 1000, 'twitter', {
|
|
388
|
+
expect(timeAgo.format(0.5 * 365 * 24 * 60 * 60 * 1000, 'twitter', {
|
|
388
389
|
getTimeToNextUpdate: true,
|
|
389
390
|
now: 0,
|
|
390
391
|
round: 'floor'
|
|
391
|
-
}).
|
|
392
|
+
})).to.deep.equal(['Jul 2', 2147483647]);
|
|
392
393
|
});
|
|
393
394
|
it('should get time to next update (capped)', function () {
|
|
394
395
|
var timeAgo = new TimeAgo('en');
|
|
395
396
|
// in 1 second -> in 0 seconds.
|
|
396
|
-
timeAgo.format(0.5 * 365 * 24 * 60 * 60 * 1000, 'twitter', {
|
|
397
|
+
expect(timeAgo.format(0.5 * 365 * 24 * 60 * 60 * 1000, 'twitter', {
|
|
397
398
|
getTimeToNextUpdate: true,
|
|
398
399
|
getTimeToNextUpdateUncapped: true,
|
|
399
400
|
now: 0,
|
|
400
401
|
round: 'floor'
|
|
401
|
-
}).
|
|
402
|
+
})).to.deep.equal(['Jul 2', 15681600001]);
|
|
402
403
|
});
|
|
403
404
|
it('should get time to next update (uncapped)', function () {
|
|
404
405
|
var timeAgo = new TimeAgo('en');
|
|
405
406
|
// in 1 second -> in 0 seconds.
|
|
406
|
-
timeAgo.format(1000, 'twitter', {
|
|
407
|
+
expect(timeAgo.format(1000, 'twitter', {
|
|
407
408
|
getTimeToNextUpdate: true,
|
|
408
409
|
now: 0,
|
|
409
410
|
round: 'floor'
|
|
410
|
-
}).
|
|
411
|
+
})).to.deep.equal(['1s', 1]);
|
|
411
412
|
});
|
|
412
413
|
it('should get time to next update (round: "floor")', function () {
|
|
413
414
|
var timeAgo = new TimeAgo('en');
|
|
414
415
|
// in 1 second -> in 0 seconds.
|
|
415
|
-
timeAgo.format(1000, 'twitter', {
|
|
416
|
+
expect(timeAgo.format(1000, 'twitter', {
|
|
416
417
|
getTimeToNextUpdate: true,
|
|
417
418
|
now: 0,
|
|
418
419
|
round: 'floor'
|
|
419
|
-
}).
|
|
420
|
+
})).to.deep.equal(['1s', 1]);
|
|
420
421
|
});
|
|
421
422
|
it('should get time to next update (round: "round")', function () {
|
|
422
423
|
var timeAgo = new TimeAgo('en');
|
|
423
424
|
// in 1 second -> in 0 seconds.
|
|
424
|
-
timeAgo.format(1000, 'twitter', {
|
|
425
|
+
expect(timeAgo.format(1000, 'twitter', {
|
|
425
426
|
getTimeToNextUpdate: true,
|
|
426
427
|
now: 0
|
|
427
|
-
}).
|
|
428
|
+
})).to.deep.equal(['1s', 501]);
|
|
428
429
|
});
|
|
429
430
|
it('should get time to next update ("mini-now" style) (round: "floor")', function () {
|
|
430
431
|
var timeAgo = new TimeAgo('en');
|
|
431
432
|
// In 1 minute.
|
|
432
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
433
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
433
434
|
getTimeToNextUpdate: true,
|
|
434
435
|
now: 0,
|
|
435
436
|
round: 'floor'
|
|
436
|
-
}).
|
|
437
|
+
})).to.deep.equal(['1m', 1]);
|
|
437
438
|
// Almost in 1 minute.
|
|
438
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
439
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
439
440
|
getTimeToNextUpdate: true,
|
|
440
441
|
now: 1,
|
|
441
442
|
round: 'floor'
|
|
442
|
-
}).
|
|
443
|
+
})).to.deep.equal(['59s', 1000]);
|
|
443
444
|
// In 1 second.
|
|
444
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
445
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
445
446
|
getTimeToNextUpdate: true,
|
|
446
447
|
now: 59 * 1000,
|
|
447
448
|
round: 'floor'
|
|
448
|
-
}).
|
|
449
|
+
})).to.deep.equal(['1s', 1]);
|
|
449
450
|
// Almost in 1 second.
|
|
450
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
451
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
451
452
|
getTimeToNextUpdate: true,
|
|
452
453
|
now: 59 * 1000 + 1,
|
|
453
454
|
round: 'floor'
|
|
454
|
-
}).
|
|
455
|
+
})).to.deep.equal(['now',
|
|
455
456
|
// Right after zero point.
|
|
456
457
|
1000]);
|
|
457
458
|
// Zero point (future to past).
|
|
458
459
|
// `future: true`.
|
|
459
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
460
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
460
461
|
getTimeToNextUpdate: true,
|
|
461
462
|
now: 60 * 1000,
|
|
462
463
|
future: true,
|
|
463
464
|
round: 'floor'
|
|
464
|
-
}).
|
|
465
|
+
})).to.deep.equal(['now', 1]);
|
|
465
466
|
// Zero point (future to past).
|
|
466
467
|
// `future: false`.
|
|
467
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
468
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
468
469
|
getTimeToNextUpdate: true,
|
|
469
470
|
now: 60 * 1000,
|
|
470
471
|
round: 'floor'
|
|
471
|
-
}).
|
|
472
|
+
})).to.deep.equal(['now', 1000]);
|
|
472
473
|
// Right after zero point (past).
|
|
473
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
474
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
474
475
|
getTimeToNextUpdate: true,
|
|
475
476
|
now: 60 * 1000 + 1,
|
|
476
477
|
round: 'floor'
|
|
477
|
-
}).
|
|
478
|
+
})).to.deep.equal(['now', 1000 - 1]);
|
|
478
479
|
// 1 second ago.
|
|
479
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
480
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
480
481
|
getTimeToNextUpdate: true,
|
|
481
482
|
now: 60 * 1000 + 1000,
|
|
482
483
|
round: 'floor'
|
|
483
|
-
}).
|
|
484
|
+
})).to.deep.equal(['1s', 1000]);
|
|
484
485
|
});
|
|
485
486
|
it('should get time to next update ("mini-now" style) (round: "round")', function () {
|
|
486
487
|
var timeAgo = new TimeAgo('en');
|
|
487
488
|
// In 1 minute.
|
|
488
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
489
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
489
490
|
getTimeToNextUpdate: true,
|
|
490
491
|
now: 0
|
|
491
|
-
}).
|
|
492
|
+
})).to.deep.equal(['1m', 500 + 1]);
|
|
492
493
|
// Almost in 1 minute.
|
|
493
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
494
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
494
495
|
getTimeToNextUpdate: true,
|
|
495
496
|
now: 500 + 1
|
|
496
|
-
}).
|
|
497
|
+
})).to.deep.equal(['59s', 1000]);
|
|
497
498
|
// In 1 second.
|
|
498
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
499
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
499
500
|
getTimeToNextUpdate: true,
|
|
500
501
|
now: 59.5 * 1000
|
|
501
|
-
}).
|
|
502
|
+
})).to.deep.equal(['1s', 1]);
|
|
502
503
|
// Almost in 1 second.
|
|
503
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
504
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
504
505
|
getTimeToNextUpdate: true,
|
|
505
506
|
now: 59.5 * 1000 + 1
|
|
506
|
-
}).
|
|
507
|
+
})).to.deep.equal(['now',
|
|
507
508
|
// Right after zero point.
|
|
508
509
|
500]);
|
|
509
510
|
// Zero point (future to past).
|
|
510
511
|
// `future: true`.
|
|
511
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
512
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
512
513
|
getTimeToNextUpdate: true,
|
|
513
514
|
now: 60 * 1000,
|
|
514
515
|
future: true
|
|
515
|
-
}).
|
|
516
|
+
})).to.deep.equal(['now', 1]);
|
|
516
517
|
// Zero point (future to past).
|
|
517
518
|
// `future: false`.
|
|
518
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
519
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
519
520
|
getTimeToNextUpdate: true,
|
|
520
521
|
now: 60 * 1000
|
|
521
|
-
}).
|
|
522
|
+
})).to.deep.equal(['now', 500]);
|
|
522
523
|
// Right after zero point (past).
|
|
523
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
524
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
524
525
|
getTimeToNextUpdate: true,
|
|
525
526
|
now: 60 * 1000 + 1
|
|
526
|
-
}).
|
|
527
|
+
})).to.deep.equal(['now', 500 - 1]);
|
|
527
528
|
// 1 second ago.
|
|
528
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
529
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
529
530
|
getTimeToNextUpdate: true,
|
|
530
531
|
now: 60 * 1000 + 500
|
|
531
|
-
}).
|
|
532
|
+
})).to.deep.equal(['1s', 1000]);
|
|
532
533
|
});
|
|
533
534
|
it('should get time to next update (first step has non-zero "minTime") (round: "floor")', function () {
|
|
534
535
|
var timeAgo = new TimeAgo('en');
|
|
@@ -536,7 +537,7 @@ describe("javascript-time-ago", function () {
|
|
|
536
537
|
// Future.
|
|
537
538
|
// Inside the first step.
|
|
538
539
|
// Updates soon.
|
|
539
|
-
timeAgo.format(60 * 1000, {
|
|
540
|
+
expect(timeAgo.format(60 * 1000, {
|
|
540
541
|
steps: [{
|
|
541
542
|
formatAs: 'minute',
|
|
542
543
|
minTime: 60
|
|
@@ -546,12 +547,12 @@ describe("javascript-time-ago", function () {
|
|
|
546
547
|
}, {
|
|
547
548
|
getTimeToNextUpdate: true,
|
|
548
549
|
now: -0.5 * 1000
|
|
549
|
-
}).
|
|
550
|
+
})).to.deep.equal(['1m', 0.5 * 1000 + 1]);
|
|
550
551
|
|
|
551
552
|
// Future.
|
|
552
553
|
// Outside of the first step.
|
|
553
554
|
// Updates right after zero point.
|
|
554
|
-
timeAgo.format(60 * 1000, {
|
|
555
|
+
expect(timeAgo.format(60 * 1000, {
|
|
555
556
|
steps: [{
|
|
556
557
|
formatAs: 'minute',
|
|
557
558
|
minTime: 60 * 1000
|
|
@@ -561,12 +562,12 @@ describe("javascript-time-ago", function () {
|
|
|
561
562
|
}, {
|
|
562
563
|
getTimeToNextUpdate: true,
|
|
563
564
|
now: 1 * 1000
|
|
564
|
-
}).
|
|
565
|
+
})).to.deep.equal(['', 59 * 1000 + 1]);
|
|
565
566
|
|
|
566
567
|
// Zero point.
|
|
567
568
|
// Outside of the first step.
|
|
568
569
|
// Updates at the first step's `minTime`.
|
|
569
|
-
timeAgo.format(60 * 1000, {
|
|
570
|
+
expect(timeAgo.format(60 * 1000, {
|
|
570
571
|
steps: [{
|
|
571
572
|
formatAs: 'minute',
|
|
572
573
|
minTime: 60
|
|
@@ -576,12 +577,12 @@ describe("javascript-time-ago", function () {
|
|
|
576
577
|
}, {
|
|
577
578
|
getTimeToNextUpdate: true,
|
|
578
579
|
now: 60 * 1000
|
|
579
|
-
}).
|
|
580
|
+
})).to.deep.equal(['', 60 * 1000]);
|
|
580
581
|
|
|
581
582
|
// Past.
|
|
582
583
|
// Inside the first step.
|
|
583
584
|
// Updates at the next minute.
|
|
584
|
-
timeAgo.format(60 * 1000, {
|
|
585
|
+
expect(timeAgo.format(60 * 1000, {
|
|
585
586
|
steps: [{
|
|
586
587
|
formatAs: 'minute',
|
|
587
588
|
minTime: 60
|
|
@@ -591,60 +592,60 @@ describe("javascript-time-ago", function () {
|
|
|
591
592
|
}, {
|
|
592
593
|
getTimeToNextUpdate: true,
|
|
593
594
|
now: 60 * 1000 + 60 * 1000
|
|
594
|
-
}).
|
|
595
|
+
})).to.deep.equal(['1m', 60 * 1000]);
|
|
595
596
|
|
|
596
597
|
// Almost in 1 minute.
|
|
597
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
598
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
598
599
|
getTimeToNextUpdate: true,
|
|
599
600
|
now: 1,
|
|
600
601
|
round: 'floor'
|
|
601
|
-
}).
|
|
602
|
+
})).to.deep.equal(['59s', 1000]);
|
|
602
603
|
// In 1 second.
|
|
603
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
604
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
604
605
|
getTimeToNextUpdate: true,
|
|
605
606
|
now: 59 * 1000,
|
|
606
607
|
round: 'floor'
|
|
607
|
-
}).
|
|
608
|
+
})).to.deep.equal(['1s', 1]);
|
|
608
609
|
// Almost in 1 second.
|
|
609
610
|
// Updates right after the zero point.
|
|
610
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
611
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
611
612
|
getTimeToNextUpdate: true,
|
|
612
613
|
now: 59 * 1000 + 1,
|
|
613
614
|
round: 'floor'
|
|
614
|
-
}).
|
|
615
|
+
})).to.deep.equal(['now', 1000]);
|
|
615
616
|
// Zero point (future to past).
|
|
616
617
|
// `future: true`.
|
|
617
618
|
// Updates right after zero point.
|
|
618
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
619
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
619
620
|
getTimeToNextUpdate: true,
|
|
620
621
|
now: 60 * 1000,
|
|
621
622
|
future: true,
|
|
622
623
|
round: 'floor'
|
|
623
|
-
}).
|
|
624
|
+
})).to.deep.equal(['now', 1]);
|
|
624
625
|
// Zero point (future to past).
|
|
625
626
|
// `future: false`.
|
|
626
627
|
// Updates at the next second.
|
|
627
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
628
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
628
629
|
getTimeToNextUpdate: true,
|
|
629
630
|
now: 60 * 1000,
|
|
630
631
|
round: 'floor'
|
|
631
|
-
}).
|
|
632
|
+
})).to.deep.equal(['now', 1000]);
|
|
632
633
|
// Right after zero point (past).
|
|
633
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
634
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
634
635
|
getTimeToNextUpdate: true,
|
|
635
636
|
now: 60 * 1000 + 1,
|
|
636
637
|
round: 'floor'
|
|
637
|
-
}).
|
|
638
|
+
})).to.deep.equal(['now', 1000 - 1]);
|
|
638
639
|
// 1 second ago.
|
|
639
|
-
timeAgo.format(60 * 1000, 'mini-now', {
|
|
640
|
+
expect(timeAgo.format(60 * 1000, 'mini-now', {
|
|
640
641
|
getTimeToNextUpdate: true,
|
|
641
642
|
now: 60 * 1000 + 1000,
|
|
642
643
|
round: 'floor'
|
|
643
|
-
}).
|
|
644
|
+
})).to.deep.equal(['1s', 1000]);
|
|
644
645
|
});
|
|
645
646
|
it('should pass `formatAs()` in `step.format()`', function () {
|
|
646
647
|
var timeAgo = new TimeAgo('en');
|
|
647
|
-
timeAgo.format(Date.now(), {
|
|
648
|
+
expect(timeAgo.format(Date.now(), {
|
|
648
649
|
labels: 'long',
|
|
649
650
|
steps: [{
|
|
650
651
|
format: function format(date, locale, _ref4) {
|
|
@@ -652,41 +653,41 @@ describe("javascript-time-ago", function () {
|
|
|
652
653
|
return formatAs('second', 1);
|
|
653
654
|
}
|
|
654
655
|
}]
|
|
655
|
-
}).
|
|
656
|
+
})).to.equal('in 1 second');
|
|
656
657
|
});
|
|
657
658
|
it('should support `polyfill: false` option', function () {
|
|
658
659
|
var timeAgo = new TimeAgo('en', {
|
|
659
660
|
polyfill: false
|
|
660
661
|
});
|
|
661
662
|
// Still uses "now" labels, even when not polyfilled.
|
|
662
|
-
timeAgo.format(0, 'round', {
|
|
663
|
+
expect(timeAgo.format(0, 'round', {
|
|
663
664
|
now: 0
|
|
664
|
-
}).
|
|
665
|
-
timeAgo.format(1000, 'round', {
|
|
665
|
+
})).to.equal('just now');
|
|
666
|
+
expect(timeAgo.format(1000, 'round', {
|
|
666
667
|
now: 0
|
|
667
|
-
}).
|
|
668
|
+
})).to.equal('in 1 second');
|
|
668
669
|
});
|
|
669
670
|
it('should not use Intl.NumberFormat if it is not available', function () {
|
|
670
671
|
var Intl = global.Intl;
|
|
671
672
|
global.Intl = undefined;
|
|
672
673
|
var timeAgo = new TimeAgo('en');
|
|
673
|
-
timeAgo.format(1000, 'round', {
|
|
674
|
+
expect(timeAgo.format(1000, 'round', {
|
|
674
675
|
now: 0
|
|
675
|
-
}).
|
|
676
|
+
})).to.equal('in 1 second');
|
|
676
677
|
global.Intl = Intl;
|
|
677
678
|
});
|
|
678
679
|
it('should format `0` in past mode by default', function () {
|
|
679
|
-
new TimeAgo('en').format(0, {
|
|
680
|
+
expect(new TimeAgo('en').format(0, {
|
|
680
681
|
labels: 'long',
|
|
681
682
|
steps: [{
|
|
682
683
|
formatAs: 'second'
|
|
683
684
|
}]
|
|
684
685
|
}, {
|
|
685
686
|
now: 0
|
|
686
|
-
}).
|
|
687
|
+
})).to.equal('0 seconds ago');
|
|
687
688
|
});
|
|
688
689
|
it('should format `0` in future mode when `future: true` option was passed', function () {
|
|
689
|
-
new TimeAgo('en').format(0, {
|
|
690
|
+
expect(new TimeAgo('en').format(0, {
|
|
690
691
|
labels: 'long',
|
|
691
692
|
steps: [{
|
|
692
693
|
formatAs: 'second'
|
|
@@ -694,7 +695,7 @@ describe("javascript-time-ago", function () {
|
|
|
694
695
|
}, {
|
|
695
696
|
now: 0,
|
|
696
697
|
future: true
|
|
697
|
-
}).
|
|
698
|
+
})).to.equal('in 0 seconds');
|
|
698
699
|
});
|
|
699
700
|
it('should throw if a step does not define `formatAs` or `format()`', function () {
|
|
700
701
|
var timeAgo = new TimeAgo('en');
|
|
@@ -706,11 +707,11 @@ describe("javascript-time-ago", function () {
|
|
|
706
707
|
}).to["throw"]('Each step must define either `formatAs` or `format()`.');
|
|
707
708
|
});
|
|
708
709
|
it('should add default locale', function () {
|
|
709
|
-
TimeAgo.getDefaultLocale().
|
|
710
|
+
expect(TimeAgo.getDefaultLocale()).to.equal('en');
|
|
710
711
|
TimeAgo.addDefaultLocale({
|
|
711
712
|
locale: 'el'
|
|
712
713
|
});
|
|
713
|
-
TimeAgo.getDefaultLocale().
|
|
714
|
+
expect(TimeAgo.getDefaultLocale()).to.equal('el');
|
|
714
715
|
// Doesn't throw an error because the same locale is already specified as default.
|
|
715
716
|
TimeAgo.addDefaultLocale({
|
|
716
717
|
locale: 'el'
|
|
@@ -725,30 +726,30 @@ describe("javascript-time-ago", function () {
|
|
|
725
726
|
});
|
|
726
727
|
it('should support "floor" rounding', function () {
|
|
727
728
|
var timeAgo = new TimeAgo('en');
|
|
728
|
-
timeAgo.format(0.9 * 1000, 'twitter', {
|
|
729
|
+
expect(timeAgo.format(0.9 * 1000, 'twitter', {
|
|
729
730
|
now: 0,
|
|
730
731
|
round: 'floor'
|
|
731
|
-
}).
|
|
732
|
-
timeAgo.format(1 * 1000, 'twitter', {
|
|
732
|
+
})).to.equal('0s');
|
|
733
|
+
expect(timeAgo.format(1 * 1000, 'twitter', {
|
|
733
734
|
now: 0,
|
|
734
735
|
round: 'floor'
|
|
735
|
-
}).
|
|
736
|
-
timeAgo.format(1.9 * 1000, 'twitter', {
|
|
736
|
+
})).to.equal('1s');
|
|
737
|
+
expect(timeAgo.format(1.9 * 1000, 'twitter', {
|
|
737
738
|
now: 0,
|
|
738
739
|
round: 'floor'
|
|
739
|
-
}).
|
|
740
|
-
timeAgo.format(2 * 1000, 'twitter', {
|
|
740
|
+
})).to.equal('1s');
|
|
741
|
+
expect(timeAgo.format(2 * 1000, 'twitter', {
|
|
741
742
|
now: 0,
|
|
742
743
|
round: 'floor'
|
|
743
|
-
}).
|
|
744
|
-
timeAgo.format(1.9 * 60 * 1000, 'twitter', {
|
|
744
|
+
})).to.equal('2s');
|
|
745
|
+
expect(timeAgo.format(1.9 * 60 * 1000, 'twitter', {
|
|
745
746
|
now: 0,
|
|
746
747
|
round: 'floor'
|
|
747
|
-
}).
|
|
748
|
-
timeAgo.format(2 * 60 * 1000, 'twitter', {
|
|
748
|
+
})).to.equal('1m');
|
|
749
|
+
expect(timeAgo.format(2 * 60 * 1000, 'twitter', {
|
|
749
750
|
now: 0,
|
|
750
751
|
round: 'floor'
|
|
751
|
-
}).
|
|
752
|
+
})).to.equal('2m');
|
|
752
753
|
});
|
|
753
754
|
});
|
|
754
755
|
function delay(delayTime) {
|