UNPKG

3.31 kBJavaScriptView Raw
1function _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; }
2
3function _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; }
4
5import twitter from './twitterMinuteNow';
6import TimeAgo from '../TimeAgo';
7import { hour, minute, day, month, year } from '../steps';
8describe('style/twitterNow', function () {
9 it('should format Twitter style relative time (English) (round: "floor")', function () {
10 var timeAgo = new TimeAgo('en'); // April 10th, 2016.
11
12 var now = new Date(2016, 3, 10, 22, 59).getTime();
13
14 var formatInterval = function formatInterval(secondsPassed) {
15 return timeAgo.format(now - secondsPassed * 1000, _objectSpread({
16 now: now
17 }, twitter, {
18 round: 'floor'
19 }));
20 };
21
22 formatInterval(0).should.equal('now');
23 formatInterval(59.9).should.equal('now');
24 formatInterval(60).should.equal('1m');
25 formatInterval(1.9 * minute).should.equal('1m');
26 formatInterval(2 * minute).should.equal('2m');
27 formatInterval(2.9 * minute).should.equal('2m');
28 formatInterval(3 * minute).should.equal('3m'); // …
29
30 formatInterval(59.9 * minute).should.equal('59m');
31 formatInterval(60 * minute).should.equal('1h');
32 formatInterval(1.9 * hour).should.equal('1h');
33 formatInterval(2 * hour).should.equal('2h');
34 formatInterval(2.9 * hour).should.equal('2h');
35 formatInterval(3 * hour).should.equal('3h'); // …
36
37 formatInterval(23.9 * hour).should.equal('23h');
38 formatInterval(day + 2 * minute + hour).should.equal('Apr 9'); // …
39 // `month` is about 30.5 days.
40
41 formatInterval(month * 3).should.equal('Jan 10');
42 formatInterval(month * 4).should.equal('Dec 11, 2015');
43 formatInterval(year).should.equal('Apr 11, 2015'); // Test future dates.
44 // `month` is about 30.5 days.
45
46 formatInterval(-1 * month * 8).should.equal('Dec 10');
47 formatInterval(-1 * month * 9).should.equal('Jan 9, 2017');
48 });
49 it('should format Twitter style relative time (English) (round: "round")', function () {
50 var timeAgo = new TimeAgo('en'); // April 10th, 2016.
51
52 var now = new Date(2016, 3, 10, 22, 59).getTime();
53
54 var formatInterval = function formatInterval(secondsPassed) {
55 return timeAgo.format(now - secondsPassed * 1000, _objectSpread({
56 now: now
57 }, twitter, {
58 round: 'round'
59 }));
60 };
61
62 formatInterval(0).should.equal('now');
63 formatInterval(29.9).should.equal('now');
64 formatInterval(30).should.equal('1m');
65 formatInterval(1.49 * minute).should.equal('1m');
66 formatInterval(1.5 * minute).should.equal('2m');
67 formatInterval(2.49 * minute).should.equal('2m');
68 formatInterval(2.5 * minute).should.equal('3m');
69 });
70});
71//# sourceMappingURL=twitterMinuteNow.test.js.map
\No newline at end of file