UNPKG

javascript-time-ago

Version:
109 lines (92 loc) 5.1 kB
"use strict"; var _mini = _interopRequireDefault(require("./mini")); var _TimeAgo = _interopRequireDefault(require("../TimeAgo")); var _steps = require("../steps"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } 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; } describe('style/mini', function () { it('should format relative date/time (round: "floor")', function () { var timeAgo = new _TimeAgo.default('en'); var formatInterval = function formatInterval(secondsPassed) { return timeAgo.format(-secondsPassed * 1000, _objectSpread({ now: 0 }, _mini.default, { 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 * _steps.minute).should.equal('1m'); formatInterval(2 * _steps.minute).should.equal('2m'); formatInterval(2.9 * _steps.minute).should.equal('2m'); formatInterval(3 * _steps.minute).should.equal('3m'); // … formatInterval(59.9 * _steps.minute).should.equal('59m'); formatInterval(60 * _steps.minute).should.equal('1h'); formatInterval(1.9 * _steps.hour).should.equal('1h'); formatInterval(2 * _steps.hour).should.equal('2h'); formatInterval(2.9 * _steps.hour).should.equal('2h'); formatInterval(3 * _steps.hour).should.equal('3h'); // … formatInterval(23.9 * _steps.hour).should.equal('23h'); formatInterval(24 * _steps.hour).should.equal('1d'); formatInterval(2 * _steps.day).should.equal('2d'); formatInterval(7 * _steps.day).should.equal('7d'); formatInterval(30 * _steps.day).should.equal('30d'); formatInterval(_steps.month).should.equal('1mo'); formatInterval(360 * _steps.day).should.equal('11mo'); formatInterval(366 * _steps.day).should.equal('1yr'); }); it('should format relative date/time (round: "round")', function () { var timeAgo = new _TimeAgo.default('en'); var formatInterval = function formatInterval(secondsPassed) { return timeAgo.format(-secondsPassed * 1000, _objectSpread({ now: 0 }, _mini.default)); }; 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 * _steps.minute).should.equal('1m'); formatInterval(1.5 * _steps.minute).should.equal('2m'); formatInterval(2.49 * _steps.minute).should.equal('2m'); formatInterval(2.5 * _steps.minute).should.equal('3m'); // … formatInterval(59.49 * _steps.minute).should.equal('59m'); formatInterval(59.5 * _steps.minute).should.equal('1h'); formatInterval(1.49 * _steps.hour).should.equal('1h'); formatInterval(1.5 * _steps.hour).should.equal('2h'); formatInterval(2.49 * _steps.hour).should.equal('2h'); formatInterval(2.5 * _steps.hour).should.equal('3h'); // … formatInterval(23.49 * _steps.hour).should.equal('23h'); formatInterval(23.5 * _steps.hour).should.equal('1d'); formatInterval(2 * _steps.day).should.equal('2d'); formatInterval(7 * _steps.day).should.equal('7d'); formatInterval(29 * _steps.day).should.equal('29d'); formatInterval(30 * _steps.day).should.equal('1mo'); formatInterval(_steps.month).should.equal('1mo'); formatInterval(350 * _steps.day).should.equal('11mo'); formatInterval(360 * _steps.day).should.equal('1yr'); formatInterval(366 * _steps.day).should.equal('1yr'); }); it('should format relative date/time (Russian)', function () { var timeAgo = new _TimeAgo.default('ru'); var formatInterval = function formatInterval(secondsPassed) { return timeAgo.format(-secondsPassed * 1000, _objectSpread({ now: 0 }, _mini.default)); }; formatInterval(0).should.equal('0 с'); formatInterval(1).should.equal('1 с'); formatInterval(_steps.minute).should.equal('1 мин'); formatInterval(_steps.hour).should.equal('1 ч'); formatInterval(_steps.day).should.equal('1 д'); formatInterval(_steps.month).should.equal('1 мес'); formatInterval(_steps.year).should.equal('1 г'); formatInterval(5 * _steps.year).should.equal('5 л'); }); }); //# sourceMappingURL=mini.test.js.map