80 lines
3.5 KiB
JavaScript
80 lines
3.5 KiB
JavaScript
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; }
|
||
|
||
import twitterStyle from './twitter';
|
||
import JavascriptTimeAgo from '../JavascriptTimeAgo';
|
||
import { day, month, year } from '../gradation';
|
||
describe('"twitter" style', function () {
|
||
it('should fallback from "tiny" to "narrow" for Twitter style for autogenerated locales', function () {
|
||
var timeAgo = new JavascriptTimeAgo('de');
|
||
timeAgo.format(Date.now() - 3 * 60 * 60 * 1000, 'twitter').should.equal('vor 3 Std.');
|
||
});
|
||
it('should format Twitter style relative time (English)', function () {
|
||
var timeAgo = new JavascriptTimeAgo('en');
|
||
var now = new Date(2016, 3, 10, 22, 59).getTime();
|
||
|
||
var elapsed = function elapsed(time) {
|
||
return timeAgo.format(now - time * 1000, _objectSpread({
|
||
now: now
|
||
}, twitterStyle));
|
||
};
|
||
|
||
elapsed(0).should.equal('');
|
||
elapsed(44.9).should.equal('');
|
||
elapsed(45.1).should.equal('1m');
|
||
elapsed(1.49 * 60).should.equal('1m');
|
||
elapsed(1.51 * 60).should.equal('2m');
|
||
elapsed(2.49 * 60).should.equal('2m');
|
||
elapsed(2.51 * 60).should.equal('3m'); // …
|
||
|
||
elapsed(59.49 * 60).should.equal('59m');
|
||
elapsed(59.51 * 60).should.equal('1h');
|
||
elapsed(1.49 * 60 * 60).should.equal('1h');
|
||
elapsed(1.51 * 60 * 60).should.equal('2h');
|
||
elapsed(2.49 * 60 * 60).should.equal('2h');
|
||
elapsed(2.51 * 60 * 60).should.equal('3h'); // …
|
||
|
||
elapsed(23.49 * 60 * 60).should.equal('23h');
|
||
elapsed(day + 2 * 60 + 60 * 60).should.equal('Apr 9'); // …
|
||
// "month" is an approximation.
|
||
|
||
elapsed(month * 3).should.equal('Jan 10');
|
||
elapsed(month * 4).should.equal('Dec 11, 2015');
|
||
elapsed(year).should.equal('Apr 11, 2015'); // Test future dates.
|
||
// "month" is an approximation.
|
||
|
||
elapsed(-1 * month * 8).should.equal('Dec 10');
|
||
elapsed(-1 * month * 9).should.equal('Jan 9, 2017');
|
||
});
|
||
it('should format Twitter style relative time (Russian)', function () {
|
||
var timeAgo = new JavascriptTimeAgo('ru');
|
||
var now = new Date(2016, 3, 10, 22, 59).getTime();
|
||
|
||
var elapsed = function elapsed(time) {
|
||
return timeAgo.format(now - time * 1000, _objectSpread({
|
||
now: now
|
||
}, twitterStyle));
|
||
};
|
||
|
||
elapsed(45.1).should.equal('1м');
|
||
elapsed(59.51 * 60).should.equal('1ч');
|
||
elapsed(day + 62 * 60).should.equal('9 апр.');
|
||
elapsed(year).should.equal('11 апр. 2015 г.');
|
||
});
|
||
it('should format Twitter style relative time (Korean)', function () {
|
||
var timeAgo = new JavascriptTimeAgo('ko');
|
||
var now = new Date(2016, 3, 10, 22, 59).getTime();
|
||
|
||
var elapsed = function elapsed(time) {
|
||
return timeAgo.format(now - time * 1000, _objectSpread({
|
||
now: now
|
||
}, twitterStyle));
|
||
};
|
||
|
||
elapsed(45.1).should.equal('1분');
|
||
elapsed(59.51 * 60).should.equal('1시간'); // elapsed(day + 62 * 60).should.equal('9 апр.')
|
||
// elapsed(year).should.equal('11 апр. 2015 г.')
|
||
});
|
||
});
|
||
//# sourceMappingURL=twitter.test.js.map
|