UNPKG

7.68 kBJavaScriptView Raw
1function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
2
3function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
4
5function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
6
7function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
9function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
10
11function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
13import round from './round';
14import TimeAgo from '../TimeAgo';
15import { day, month, year } from '../steps';
16describe('style/round', function () {
17 it('should format relative time (English) (round: "floor")', function () {
18 var timeAgo = new TimeAgo('en');
19 var now = new Date(2016, 3, 10, 22, 59).getTime();
20
21 var formatInterval = function formatInterval(secondsPassed) {
22 return timeAgo.format(now - secondsPassed * 1000, _objectSpread({
23 now: now
24 }, round, {
25 round: 'floor'
26 }));
27 };
28
29 formatInterval(0).should.equal('just now');
30 formatInterval(0.9).should.equal('just now');
31 formatInterval(1).should.equal('1 second ago');
32 formatInterval(59.9).should.equal('59 seconds ago');
33 formatInterval(60).should.equal('1 minute ago');
34 formatInterval(1.9 * 60).should.equal('1 minute ago');
35 formatInterval(2 * 60).should.equal('2 minutes ago');
36 formatInterval(2.9 * 60).should.equal('2 minutes ago');
37 formatInterval(3 * 60).should.equal('3 minutes ago'); // …
38
39 formatInterval(59.9 * 60).should.equal('59 minutes ago');
40 formatInterval(60 * 60).should.equal('1 hour ago');
41 formatInterval(1.9 * 60 * 60).should.equal('1 hour ago');
42 formatInterval(2 * 60 * 60).should.equal('2 hours ago');
43 formatInterval(2.9 * 60 * 60).should.equal('2 hours ago');
44 formatInterval(3 * 60 * 60).should.equal('3 hours ago'); // …
45
46 formatInterval(23.9 * 60 * 60).should.equal('23 hours ago');
47 formatInterval(24 * 60 * 60).should.equal('1 day ago');
48 formatInterval(1.9 * day).should.equal('1 day ago');
49 formatInterval(2 * day).should.equal('2 days ago');
50 formatInterval(2.9 * day).should.equal('2 days ago');
51 formatInterval(3 * day).should.equal('3 days ago'); // …
52
53 formatInterval(6.9 * day).should.equal('6 days ago');
54 formatInterval(7 * day).should.equal('1 week ago'); // …
55
56 formatInterval(3.9 * 7 * day).should.equal('3 weeks ago');
57 formatInterval(4 * 7 * day).should.equal('4 weeks ago');
58 formatInterval(30.51 * day).should.equal('1 month ago');
59 formatInterval(1.9 * month).should.equal('1 month ago');
60 formatInterval(2 * month).should.equal('2 months ago');
61 formatInterval(2.9 * month).should.equal('2 months ago');
62 formatInterval(3 * month).should.equal('3 months ago'); // …
63
64 formatInterval(11.9 * month).should.equal('11 months ago');
65 formatInterval(12 * month).should.equal('1 year ago');
66 formatInterval(1.99 * year).should.equal('1 year ago');
67 formatInterval(2 * year).should.equal('2 years ago'); // …
68 // Test future dates.
69
70 formatInterval(-1 * 3).should.equal('in 3 seconds');
71 formatInterval(-1 * month * 8).should.equal('in 8 months');
72 });
73 it('should format relative time (English) (round: "round")', function () {
74 var timeAgo = new TimeAgo('en');
75 var now = new Date(2016, 3, 10, 22, 59).getTime();
76
77 var formatInterval = function formatInterval(secondsPassed) {
78 return timeAgo.format(now - secondsPassed * 1000, _objectSpread({
79 now: now
80 }, round, {
81 round: 'round'
82 }));
83 };
84
85 formatInterval(0).should.equal('just now');
86 formatInterval(0.49).should.equal('just now');
87 formatInterval(0.5).should.equal('1 second ago');
88 formatInterval(59.49).should.equal('59 seconds ago');
89 formatInterval(59.5).should.equal('1 minute ago');
90 formatInterval(1.49 * 60).should.equal('1 minute ago');
91 formatInterval(1.5 * 60).should.equal('2 minutes ago');
92 formatInterval(2.49 * 60).should.equal('2 minutes ago');
93 formatInterval(2.5 * 60).should.equal('3 minutes ago'); // …
94
95 formatInterval(59.49 * 60).should.equal('59 minutes ago');
96 formatInterval(59.5 * 60).should.equal('1 hour ago');
97 formatInterval(1.49 * 60 * 60).should.equal('1 hour ago');
98 formatInterval(1.5 * 60 * 60).should.equal('2 hours ago');
99 formatInterval(2.49 * 60 * 60).should.equal('2 hours ago');
100 formatInterval(2.5 * 60 * 60).should.equal('3 hours ago'); // …
101
102 formatInterval(23.49 * 60 * 60).should.equal('23 hours ago');
103 formatInterval(23.5 * 60 * 60).should.equal('1 day ago');
104 formatInterval(1.49 * day).should.equal('1 day ago');
105 formatInterval(1.5 * day).should.equal('2 days ago');
106 formatInterval(2.49 * day).should.equal('2 days ago');
107 formatInterval(2.5 * day).should.equal('3 days ago'); // …
108
109 formatInterval(6.49 * day).should.equal('6 days ago');
110 formatInterval(6.5 * day).should.equal('1 week ago'); // …
111
112 formatInterval(3.49 * 7 * day).should.equal('3 weeks ago');
113 formatInterval(3.5 * 7 * day).should.equal('4 weeks ago');
114 formatInterval(30.51 * day).should.equal('1 month ago');
115 formatInterval(1.49 * month).should.equal('1 month ago');
116 formatInterval(1.5 * month).should.equal('2 months ago');
117 formatInterval(2.49 * month).should.equal('2 months ago');
118 formatInterval(2.5 * month).should.equal('3 months ago'); // …
119
120 formatInterval(11.49 * month).should.equal('11 months ago');
121 formatInterval(11.5 * month).should.equal('1 year ago');
122 formatInterval(1.49 * year).should.equal('1 year ago');
123 formatInterval(1.5 * year).should.equal('2 years ago'); // …
124 // Test future dates.
125
126 formatInterval(-1 * 3).should.equal('in 3 seconds');
127 formatInterval(-1 * month * 8).should.equal('in 8 months');
128 });
129 it('should return correct update interval (round: "floor")', function () {
130 var timeAgo = new TimeAgo('en');
131
132 var _timeAgo$format = timeAgo.format(0, round, {
133 now: 0,
134 getTimeToNextUpdate: true,
135 round: 'floor'
136 }),
137 _timeAgo$format2 = _slicedToArray(_timeAgo$format, 2),
138 formattedDate = _timeAgo$format2[0],
139 timeToNextUpdate = _timeAgo$format2[1];
140
141 timeToNextUpdate.should.equal(1000);
142 });
143 it('should return correct update interval (round: "round")', function () {
144 var timeAgo = new TimeAgo('en');
145
146 var _timeAgo$format3 = timeAgo.format(0, round, {
147 now: 0,
148 getTimeToNextUpdate: true
149 }),
150 _timeAgo$format4 = _slicedToArray(_timeAgo$format3, 2),
151 formattedDate = _timeAgo$format4[0],
152 timeToNextUpdate = _timeAgo$format4[1];
153
154 timeToNextUpdate.should.equal(500);
155 });
156});
157//# sourceMappingURL=round.test.js.map
\No newline at end of file