1 | function _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 |
|
3 | function _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 |
|
5 | import roundMinute from './roundMinute';
|
6 | import TimeAgo from '../TimeAgo';
|
7 | import { day, month, year } from '../steps';
|
8 | describe('style/round-minute', function () {
|
9 | it('should format relative time (English) (round: "floor")', function () {
|
10 | var timeAgo = new TimeAgo('en');
|
11 | var now = new Date(2016, 3, 10, 22, 59).getTime();
|
12 |
|
13 | var formatInterval = function formatInterval(secondsPassed) {
|
14 | return timeAgo.format(now - secondsPassed * 1000, _objectSpread({
|
15 | now: now
|
16 | }, roundMinute, {
|
17 | round: 'floor'
|
18 | }));
|
19 | };
|
20 |
|
21 | formatInterval(0).should.equal('just now');
|
22 | formatInterval(0.9).should.equal('just now');
|
23 | formatInterval(1).should.equal('just now');
|
24 | formatInterval(59.9).should.equal('just now');
|
25 | formatInterval(60).should.equal('1 minute ago');
|
26 | formatInterval(1.9 * 60).should.equal('1 minute ago');
|
27 | formatInterval(2 * 60).should.equal('2 minutes ago');
|
28 | formatInterval(2.9 * 60).should.equal('2 minutes ago');
|
29 | formatInterval(3 * 60).should.equal('3 minutes ago');
|
30 |
|
31 | formatInterval(59.9 * 60).should.equal('59 minutes ago');
|
32 | formatInterval(60 * 60).should.equal('1 hour ago');
|
33 | formatInterval(1.9 * 60 * 60).should.equal('1 hour ago');
|
34 | formatInterval(2 * 60 * 60).should.equal('2 hours ago');
|
35 | formatInterval(2.9 * 60 * 60).should.equal('2 hours ago');
|
36 | formatInterval(3 * 60 * 60).should.equal('3 hours ago');
|
37 |
|
38 | formatInterval(23.9 * 60 * 60).should.equal('23 hours ago');
|
39 | formatInterval(24 * 60 * 60).should.equal('1 day ago');
|
40 | formatInterval(1.9 * day).should.equal('1 day ago');
|
41 | formatInterval(2 * day).should.equal('2 days ago');
|
42 | formatInterval(2.9 * day).should.equal('2 days ago');
|
43 | formatInterval(3 * day).should.equal('3 days ago');
|
44 |
|
45 | formatInterval(6.9 * day).should.equal('6 days ago');
|
46 | formatInterval(7 * day).should.equal('1 week ago');
|
47 |
|
48 | formatInterval(3.9 * 7 * day).should.equal('3 weeks ago');
|
49 | formatInterval(4 * 7 * day).should.equal('4 weeks ago');
|
50 | formatInterval(30.51 * day).should.equal('1 month ago');
|
51 | formatInterval(1.9 * month).should.equal('1 month ago');
|
52 | formatInterval(2 * month).should.equal('2 months ago');
|
53 | formatInterval(2.9 * month).should.equal('2 months ago');
|
54 | formatInterval(3 * month).should.equal('3 months ago');
|
55 |
|
56 | formatInterval(11.9 * month).should.equal('11 months ago');
|
57 | formatInterval(12 * month).should.equal('1 year ago');
|
58 | formatInterval(1.99 * year).should.equal('1 year ago');
|
59 | formatInterval(2 * year).should.equal('2 years ago');
|
60 |
|
61 |
|
62 | formatInterval(-1 * 3 * 60).should.equal('in 3 minutes');
|
63 | formatInterval(-1 * month * 8).should.equal('in 8 months');
|
64 | });
|
65 | it('should format relative time (English)', function () {
|
66 | var timeAgo = new TimeAgo('en');
|
67 | var now = new Date(2016, 3, 10, 22, 59).getTime();
|
68 |
|
69 | var formatInterval = function formatInterval(secondsPassed) {
|
70 | return timeAgo.format(now - secondsPassed * 1000, _objectSpread({
|
71 | now: now
|
72 | }, roundMinute));
|
73 | };
|
74 |
|
75 | formatInterval(0).should.equal('just now');
|
76 | formatInterval(0.49).should.equal('just now');
|
77 | formatInterval(0.5).should.equal('just now');
|
78 | formatInterval(29.9).should.equal('just now');
|
79 | formatInterval(30).should.equal('1 minute ago');
|
80 | formatInterval(1.49 * 60).should.equal('1 minute ago');
|
81 | formatInterval(1.5 * 60).should.equal('2 minutes ago');
|
82 | formatInterval(2.49 * 60).should.equal('2 minutes ago');
|
83 | formatInterval(2.5 * 60).should.equal('3 minutes ago');
|
84 | });
|
85 | });
|
86 |
|
\ | No newline at end of file |