javascript-time-ago
Version:
Localized relative date/time formatting
50 lines (49 loc) • 3.66 kB
JavaScript
;
var _miniMinuteNow = _interopRequireDefault(require("./miniMinuteNow.js"));
var _TimeAgo = _interopRequireDefault(require("../TimeAgo.js"));
var _index = require("../steps/index.js");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
describe('style/mini-minute-now', 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(_objectSpread({
now: 0
}, _miniMinuteNow["default"]), {}, {
round: 'floor'
}));
};
formatInterval(0).should.equal('now');
formatInterval(0.9).should.equal('now');
formatInterval(1).should.equal('now');
formatInterval(59.9).should.equal('now');
formatInterval(60).should.equal('1m');
formatInterval(1.9 * _index.minute).should.equal('1m');
formatInterval(2 * _index.minute).should.equal('2m');
formatInterval(2.9 * _index.minute).should.equal('2m');
formatInterval(3 * _index.minute).should.equal('3m');
// …
formatInterval(59.9 * _index.minute).should.equal('59m');
formatInterval(60 * _index.minute).should.equal('1h');
formatInterval(1.9 * _index.hour).should.equal('1h');
formatInterval(2 * _index.hour).should.equal('2h');
formatInterval(2.9 * _index.hour).should.equal('2h');
formatInterval(3 * _index.hour).should.equal('3h');
// …
formatInterval(23.9 * _index.hour).should.equal('23h');
formatInterval(24 * _index.hour).should.equal('1d');
formatInterval(2 * _index.day).should.equal('2d');
formatInterval(7 * _index.day).should.equal('7d');
formatInterval(30 * _index.day).should.equal('30d');
formatInterval(_index.month).should.equal('1mo');
formatInterval(360 * _index.day).should.equal('11mo');
formatInterval(366 * _index.day).should.equal('1yr');
});
});
//# sourceMappingURL=miniMinuteNow.test.js.map