UNPKG

javascript-time-ago

Version:

Localized relative date/time formatting

98 lines 5.56 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import style from './mini.js'; import TimeAgo from '../TimeAgo.js'; import { hour, minute, day, month, year } from '../steps/index.js'; describe('style/mini', function () { it('should format relative date/time (round: "floor")', function () { var timeAgo = new TimeAgo('en'); var formatInterval = function formatInterval(secondsPassed) { return timeAgo.format(-secondsPassed * 1000, _objectSpread(_objectSpread({ now: 0 }, style), {}, { round: 'floor' })); }; formatInterval(0).should.equal('0s'); formatInterval(0.9).should.equal('0s'); formatInterval(1).should.equal('1s'); formatInterval(59.9).should.equal('59s'); formatInterval(60).should.equal('1m'); formatInterval(1.9 * minute).should.equal('1m'); formatInterval(2 * minute).should.equal('2m'); formatInterval(2.9 * minute).should.equal('2m'); formatInterval(3 * minute).should.equal('3m'); // … formatInterval(59.9 * minute).should.equal('59m'); formatInterval(60 * minute).should.equal('1h'); formatInterval(1.9 * hour).should.equal('1h'); formatInterval(2 * hour).should.equal('2h'); formatInterval(2.9 * hour).should.equal('2h'); formatInterval(3 * hour).should.equal('3h'); // … formatInterval(23.9 * hour).should.equal('23h'); formatInterval(24 * hour).should.equal('1d'); formatInterval(2 * day).should.equal('2d'); formatInterval(7 * day).should.equal('7d'); formatInterval(30 * day).should.equal('30d'); formatInterval(month).should.equal('1mo'); formatInterval(360 * day).should.equal('11mo'); formatInterval(366 * day).should.equal('1yr'); }); it('should format relative date/time (round: "round")', function () { var timeAgo = new TimeAgo('en'); var formatInterval = function formatInterval(secondsPassed) { return timeAgo.format(-secondsPassed * 1000, _objectSpread({ now: 0 }, style)); }; formatInterval(0).should.equal('0s'); formatInterval(0.49).should.equal('0s'); formatInterval(0.5).should.equal('1s'); formatInterval(59.49).should.equal('59s'); formatInterval(59.5).should.equal('1m'); formatInterval(1.49 * minute).should.equal('1m'); formatInterval(1.5 * minute).should.equal('2m'); formatInterval(2.49 * minute).should.equal('2m'); formatInterval(2.5 * minute).should.equal('3m'); // … formatInterval(59.49 * minute).should.equal('59m'); formatInterval(59.5 * minute).should.equal('1h'); formatInterval(1.49 * hour).should.equal('1h'); formatInterval(1.5 * hour).should.equal('2h'); formatInterval(2.49 * hour).should.equal('2h'); formatInterval(2.5 * hour).should.equal('3h'); // … formatInterval(23.49 * hour).should.equal('23h'); formatInterval(23.5 * hour).should.equal('1d'); formatInterval(2 * day).should.equal('2d'); formatInterval(7 * day).should.equal('7d'); formatInterval(29 * day).should.equal('29d'); formatInterval(30 * day).should.equal('1mo'); formatInterval(month).should.equal('1mo'); formatInterval(350 * day).should.equal('11mo'); formatInterval(360 * day).should.equal('1yr'); formatInterval(366 * day).should.equal('1yr'); }); it('should format relative date/time (Russian)', function () { var timeAgo = new TimeAgo('ru'); var formatInterval = function formatInterval(secondsPassed) { return timeAgo.format(-secondsPassed * 1000, _objectSpread({ now: 0 }, style)); }; formatInterval(0).should.equal('0 с'); formatInterval(1).should.equal('1 с'); formatInterval(minute).should.equal('1 мин'); formatInterval(hour).should.equal('1 ч'); formatInterval(day).should.equal('1 д'); formatInterval(month).should.equal('1 мес'); formatInterval(year).should.equal('1 г'); formatInterval(5 * year).should.equal('5 л'); }); }); //# sourceMappingURL=mini.test.js.map