javascript-time-ago
Version:
Localized relative date/time formatting
54 lines (43 loc) • 2.67 kB
JavaScript
;
var _miniNow = _interopRequireDefault(require("./miniNow"));
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-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({
now: 0
}, _miniNow.default, {
round: 'floor'
}));
};
formatInterval(0).should.equal('now');
formatInterval(0.9).should.equal('now');
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');
});
});
//# sourceMappingURL=miniNow.test.js.map