pax_global_header 0000666 0000000 0000000 00000000064 13577310712 0014520 g ustar 00root root 0000000 0000000 52 comment=bb55152bd64a5635500e36fb0c32c66fbacae140
timeago.js-4.0.2/ 0000775 0000000 0000000 00000000000 13577310712 0013563 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/.commitlintrc.js 0000664 0000000 0000000 00000000306 13577310712 0016702 0 ustar 00root root 0000000 0000000 module.exports = {
rules: {
'type-enum': [
2,
'always',
['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test', 'wip'],
],
},
};
timeago.js-4.0.2/.eslintrc 0000664 0000000 0000000 00000000663 13577310712 0015414 0 ustar 00root root 0000000 0000000 {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.ci.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/ban-ts-ignore": 1,
"@typescript-eslint/camelcase": 0
}
}
timeago.js-4.0.2/.github/ 0000775 0000000 0000000 00000000000 13577310712 0015123 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/.github/FUNDING.yml 0000664 0000000 0000000 00000001261 13577310712 0016740 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://paypal.me/hustcc', 'https://atool.vip']
timeago.js-4.0.2/.github/workflows/ 0000775 0000000 0000000 00000000000 13577310712 0017160 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/.github/workflows/build.yml 0000664 0000000 0000000 00000001123 13577310712 0020777 0 ustar 00root root 0000000 0000000 name: build
on: [push]
jobs:
build:
runs-on: macOS-latest
strategy:
matrix:
node-version: [8.x,9.x,10.x,11.x,12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install and ci
run: |
npm install
npm run build
npm run ci
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
timeago.js-4.0.2/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000457 13577310712 0021152 0 ustar 00root root 0000000 0000000 on:
issue_comment:
types: [created]
name: Automatic Rebase
jobs:
rebase:
name: Rebase
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Automatic Rebase
uses: cirrus-actions/rebase@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
timeago.js-4.0.2/.github/workflows/release.yml 0000664 0000000 0000000 00000002445 13577310712 0021330 0 ustar 00root root 0000000 0000000 name: Release
on:
release:
types: [created, edited]
jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
- run: npm run build
- run: npm run ci
publish-site:
needs: build
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm install
- run: npm run build
- run: |
cd gh-pages
git init
git config --local user.name action
git config --local user.email i@hust.cc
git add .
git commit -m "update by release action"
- uses: ad-m/github-push-action@master
with:
github_token: ${{secrets.GITHUB_TOKEN}}
directory: gh-pages
branch: gh-pages
force: true
publish-npm:
needs: build
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
timeago.js-4.0.2/.gitignore 0000664 0000000 0000000 00000000154 13577310712 0015553 0 ustar 00root root 0000000 0000000 node_modules/
npm-debug.*
.idea
coverage
package-lock.json
lib
esm
dist
timeago.full.min.js
timeago.min.js
timeago.js-4.0.2/.prettierrc 0000664 0000000 0000000 00000000216 13577310712 0015746 0 ustar 00root root 0000000 0000000 {
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"printWidth": 120,
"arrowParens": "always"
}
timeago.js-4.0.2/LICENSE 0000664 0000000 0000000 00000002061 13577310712 0014567 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2016 Hust.cc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. timeago.js-4.0.2/README.md 0000664 0000000 0000000 00000011732 13577310712 0015046 0 ustar 00root root 0000000 0000000 # timeago.js
> **timeago.js** is a nano library(less than `2 kb`) used to format datetime with `*** time ago` statement. eg: '3 hours ago'.
- i18n supported.
- Time `ago` and time `in` supported.
- Real-time render supported.
- Node and browser supported.
- Well tested.
[Official website](https://timeago.org/). React version here: [timeago-react](https://github.com/hustcc/timeago-react). Python version here: [timeago](https://github.com/hustcc/timeago).
[](https://www.npmjs.com/package/timeago.js)
[](https://unpkg.com/browse/timeago.js/)
[](https://github.com/hustcc/timeago.js/actions)
[](https://coveralls.io/github/hustcc/timeago.js?branch=master)
[](https://unpkg.com/timeago.js/dist/timeago.min.js)
[](https://www.npmjs.com/package/timeago.js)
[](https://www.npmjs.com/package/timeago.js)
Such as
```plain
just now
12 seconds ago
2 hours ago
3 days ago
3 weeks ago
2 years ago
in 12 seconds
in 3 minutes
in 24 days
in 6 months
```
## Usage
- install
```bash
npm install timeago.js
```
- import
```ts
import { format, render, cancel, register } from 'timeago.js';
```
or import with `script` tag in html file and access global variable `timeago`.
```html
```
- example
```ts
// format the time with locale
format('2016-06-12', 'en_US');
```
## API
There only 4 API below.
- **format**
> `format(date[, locale = 'en_US', opts])`, format a Date instance / timestamp / date string to string.
```ts
import { format } from 'timeago.js';
// format timestamp
format(1544666010224);
// format date instance
format(new Date(1544666010224));
// format date string
format('2018-12-12');
// format with locale
format(1544666010224, 'zh_CN');
// format with locale and relative date
format(1544666010224, 'zh_CN', { relativeDate: '2018-11-11' });
// e.g.
format(Date.now() - 11 * 1000 * 60 * 60); // returns '11 hours ago'
```
The default locale is `en_US`, and the library contains `en_US` and `zh_CN` build-in.
- **render** & **cancel**
> `render(dom[, locale = 'en_US', opts])`
> `cancel([dom])`
> Make a dom with `datetime` attribute automatic rendering and cancel.
HTML code:
```html
```
Javascript code:
```ts
import { render, cancel } from 'timeago.js';
const nodes = document.querySelectorAll('.timeago');
// use render method to render nodes in real time
render(nodes, 'zh_CN');
// render with opts
// render(nodes, 'en_US', { minInterval: 3 });
// cancel all real-time render task
cancel();
// or cancel for the specific one
cancel(nodes[0])
```
The 3rd parameter `opts` contains:
```ts
export type Opts = {
/** the relative date */
readonly relativeDate?: TDate;
/** the realtime min update interval */
readonly minInterval?: number;
};
```
> The DOM object should have the attribute `datetime` with date formatted string.
- **register**
> `register(locale, localeFunc)`, register a new locale, build-in locale contains: `en_US`, `zh_CN`, [all locales here](src/lang).
You can register your own language with `register` API.
```ts
const localeFunc = (number: number, index: number, totalSec: number): [string, string] => {
// number: the timeago / timein number;
// index: the index of array below;
// totalSec: total seconds between date to be formatted and today's date;
return [
['just now', 'right now'],
['%s seconds ago', 'in %s seconds'],
['1 minute ago', 'in 1 minute'],
['%s minutes ago', 'in %s minutes'],
['1 hour ago', 'in 1 hour'],
['%s hours ago', 'in %s hours'],
['1 day ago', 'in 1 day'],
['%s days ago', 'in %s days'],
['1 week ago', 'in 1 week'],
['%s weeks ago', 'in %s weeks'],
['1 month ago', 'in 1 month'],
['%s months ago', 'in %s months'],
['1 year ago', 'in 1 year'],
['%s years ago', 'in %s years']
][index];
};
// register your locale with timeago
register('my-locale', localeFunc);
// use it
format('2016-06-12', 'my-locale');
```
## Contributions
1. The website is based on [rmm5t/jquery-timeago](https://github.com/rmm5t/jquery-timeago) which is a nice and featured project but it depends on jQuery.
2. **locale translations**: The library needs more locale translations. You can:
- Open an issue to write the locale translations, or submit a pull request. How to ? see [locales translation](src/lang/).
- Please **test** the locale by exec `npm test`. How to write test cases, see [locales test cases](__tests__/lang/).
## LICENSE
MIT@[hustcc](https://github.com/hustcc)
timeago.js-4.0.2/__tests__/ 0000775 0000000 0000000 00000000000 13577310712 0015521 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/__tests__/format.spec.ts 0000664 0000000 0000000 00000001123 13577310712 0020307 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { format } from '../src/';
describe('format', () => {
test('format', () => {
const now = new Date();
expect(format(+now - 5000)).toBe('just now');
expect(format(+now - 5000, undefined, { relativeDate: now })).toBe('just now');
expect(format(+now - 1000 * 1000, 'zh_CN')).toBe('16 分钟前');
expect(format(+now - 1000 * 1000, 'zh_CN', { relativeDate: now })).toBe('16 分钟前');
expect(format(+now - 1000 * 1000, 'not-exist-locale', { relativeDate: now })).toBe('16 minutes ago');
});
});
timeago.js-4.0.2/__tests__/full.spec.ts 0000664 0000000 0000000 00000001142 13577310712 0017762 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { format, render, cancel, register } from '../src/full';
import * as Locales from '../src/lang';
import { getLocale } from '../src/register';
describe('timeago.js full', () => {
test('export', () => {
expect(format).toBeInstanceOf(Function);
expect(render).toBeInstanceOf(Function);
expect(cancel).toBeInstanceOf(Function);
expect(register).toBeInstanceOf(Function);
});
test('locales', () => {
Object.keys(Locales).forEach((key: string) => {
expect(getLocale(key)).toBe(Locales[key]);
});
});
});
timeago.js-4.0.2/__tests__/helper.ts 0000664 0000000 0000000 00000000703 13577310712 0017350 0 ustar 00root root 0000000 0000000 /**
* 创建一个 time 节点
*/
export function createTimeNode(timestamp?: number): HTMLElement {
const time = document.createElement('time');
document.body.append(time);
if (timestamp) time.setAttribute('datetime', `${timestamp}`);
return time;
}
/**
* 延迟 ms
* @param ms
*/
export function delay(ms = 1100): Promise {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms);
});
}
timeago.js-4.0.2/__tests__/index.spec.ts 0000664 0000000 0000000 00000005740 13577310712 0020137 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { format, render, cancel, register } from '../src/';
import { getLocale } from '../src/register';
describe('timeago.js core', () => {
test('export', () => {
expect(format).toBeInstanceOf(Function);
expect(render).toBeInstanceOf(Function);
expect(cancel).toBeInstanceOf(Function);
expect(register).toBeInstanceOf(Function);
});
describe('built-in locales', () => {
test('getLocale', () => {
expect(getLocale('zh_CN')).toBeDefined();
expect(getLocale('en_US')).toBeDefined();
});
test('Locales zh_CN', () => {
expect(getLocale('zh_CN')(1, 0)).toEqual(['刚刚', '片刻后']);
expect(getLocale('zh_CN')(1, 1)).toEqual(['1 秒前', '1 秒后']);
expect(getLocale('zh_CN')(1, 2)).toEqual(['1 分钟前', '1 分钟后']);
expect(getLocale('zh_CN')(1, 3)).toEqual(['1 分钟前', '1 分钟后']);
expect(getLocale('zh_CN')(1, 4)).toEqual(['1 小时前', '1 小时后']);
expect(getLocale('zh_CN')(1, 5)).toEqual(['1 小时前', '1 小时后']);
expect(getLocale('zh_CN')(1, 6)).toEqual(['1 天前', '1 天后']);
expect(getLocale('zh_CN')(1, 7)).toEqual(['1 天前', '1 天后']);
expect(getLocale('zh_CN')(1, 8)).toEqual(['1 周前', '1 周后']);
expect(getLocale('zh_CN')(1, 9)).toEqual(['1 周前', '1 周后']);
expect(getLocale('zh_CN')(1, 10)).toEqual(['1 个月前', '1 个月后']);
expect(getLocale('zh_CN')(1, 11)).toEqual(['1 个月前', '1 个月后']);
expect(getLocale('zh_CN')(1, 12)).toEqual(['1 年前', '1 年后']);
expect(getLocale('zh_CN')(1, 13)).toEqual(['1 年前', '1 年后']);
});
test('Locales en_US', () => {
expect(getLocale('en_US')(1, 0)).toEqual(['just now', 'right now']);
expect(getLocale('en_US')(1, 1)).toEqual(['1 second ago', 'in 1 second']);
expect(getLocale('en_US')(10, 1)).toEqual(['10 seconds ago', 'in 10 seconds']);
expect(getLocale('en_US')(1, 2)).toEqual(['1 minute ago', 'in 1 minute']);
expect(getLocale('en_US')(1, 3)).toEqual(['1 minute ago', 'in 1 minute']);
expect(getLocale('en_US')(1, 4)).toEqual(['1 hour ago', 'in 1 hour']);
expect(getLocale('en_US')(1, 5)).toEqual(['1 hour ago', 'in 1 hour']);
expect(getLocale('en_US')(1, 6)).toEqual(['1 day ago', 'in 1 day']);
expect(getLocale('en_US')(1, 7)).toEqual(['1 day ago', 'in 1 day']);
expect(getLocale('en_US')(1, 8)).toEqual(['1 week ago', 'in 1 week']);
expect(getLocale('en_US')(1, 9)).toEqual(['1 week ago', 'in 1 week']);
expect(getLocale('en_US')(1, 10)).toEqual(['1 month ago', 'in 1 month']);
expect(getLocale('en_US')(1, 11)).toEqual(['1 month ago', 'in 1 month']);
expect(getLocale('en_US')(1, 12)).toEqual(['1 year ago', 'in 1 year']);
expect(getLocale('en_US')(1, 13)).toEqual(['1 year ago', 'in 1 year']);
expect(getLocale('en_US')(10, 13)).toEqual(['10 years ago', 'in 10 years']);
});
});
});
timeago.js-4.0.2/__tests__/lang/ 0000775 0000000 0000000 00000000000 13577310712 0016442 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/__tests__/lang/cs.spec.ts 0000664 0000000 0000000 00000011314 13577310712 0020350 0 ustar 00root root 0000000 0000000 import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import cs from '../../src/lang/cs';
register('cs', cs);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('cs', () => {
describe('time ago', () => {
test('just now', () => {
advanceTo(9 * 1000);
expect(format(date, 'cs')).toEqual('právě teď');
});
test('seconds', () => {
advanceTo(30 * 1000);
expect(format(date, 'cs')).toEqual('před 30 vteřinami');
});
test('minute', () => {
advanceTo(1000 * 60);
expect(format(date, 'cs')).toEqual('před minutou');
});
test('minutes', () => {
advanceTo(1000 * 60 * 30);
expect(format(date, 'cs')).toEqual('před 30 minutami');
});
test('hour', () => {
advanceTo(1000 * 60 * 60);
expect(format(date, 'cs')).toEqual('před hodinou');
});
test('hours', () => {
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'cs')).toEqual('před 8 hodinami');
});
test('yesterday', () => {
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'cs')).toEqual('včera');
});
test('days', () => {
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'cs')).toEqual('před 3 dny');
});
test('last week', () => {
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'cs')).toEqual('minulý týden');
});
test('weeks', () => {
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'cs')).toEqual('před 3 týdny');
});
test('last month', () => {
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'cs')).toEqual('minulý měsíc');
});
test('months', () => {
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'cs')).toEqual('před 4 měsíci');
});
test('last year', () => {
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'cs')).toEqual('před rokem');
});
test('years', () => {
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'cs')).toEqual('před 10 lety');
});
});
describe('time in', () => {
test('just now', () => {
advanceTo(-9 * 1000);
expect(format(date, 'cs')).toEqual('právě teď');
});
test('seconds', () => {
advanceTo(-30 * 1000);
expect(format(date, 'cs')).toEqual('za 30 vteřin');
});
test('minute', () => {
advanceTo(-1000 * 60);
expect(format(date, 'cs')).toEqual('za minutu');
});
test('4 minutes', () => {
advanceTo(-1000 * 60 * 4);
expect(format(date, 'cs')).toEqual('za 4 minuty');
});
test('5 minutes', () => {
advanceTo(-1000 * 60 * 5);
expect(format(date, 'cs')).toEqual('za 5 minut');
});
test('hour', () => {
advanceTo(-1000 * 60 * 60);
expect(format(date, 'cs')).toEqual('za hodinu');
});
test('4 hours', () => {
advanceTo(-1000 * 60 * 60 * 4);
expect(format(date, 'cs')).toEqual('za 4 hodiny');
});
test('5 hours', () => {
advanceTo(-1000 * 60 * 60 * 5);
expect(format(date, 'cs')).toEqual('za 5 hodin');
});
test('tomorrow', () => {
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'cs')).toEqual('zítra');
});
test('4 days', () => {
advanceTo(-1000 * 60 * 60 * 24 * 4);
expect(format(date, 'cs')).toEqual('za 4 dny');
});
test('5 days', () => {
advanceTo(-1000 * 60 * 60 * 24 * 5);
expect(format(date, 'cs')).toEqual('za 5 dnů');
});
test('next week', () => {
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'cs')).toEqual('příští týden');
});
test('4 weeks', () => {
advanceTo(-1000 * 60 * 60 * 24 * 7 * 4);
expect(format(date, 'cs')).toEqual('za 4 týdny');
});
test('next month', () => {
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'cs')).toEqual('přístí měsíc');
});
test('4 months', () => {
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'cs')).toEqual('za 4 měsíce');
});
test('5 months', () => {
advanceTo(-1000 * 60 * 60 * 24 * 31 * 5);
expect(format(date, 'cs')).toEqual('za 5 měsíců');
});
test('next year', () => {
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'cs')).toEqual('přístí rok');
});
test('4 years', () => {
advanceTo(-1000 * 60 * 60 * 24 * 366 * 4);
expect(format(date, 'cs')).toEqual('za 4 roky');
});
test('5 years', () => {
advanceTo(-1000 * 60 * 60 * 24 * 366 * 5);
expect(format(date, 'cs')).toEqual('za 5 let');
});
});
});
timeago.js-4.0.2/__tests__/lang/fa.spec.ts 0000664 0000000 0000000 00000006160 13577310712 0020334 0 ustar 00root root 0000000 0000000 import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import fa from '../../src/lang/fa';
register('fa', fa);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('fa', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'fa')).toEqual('لحظاتی پیش');
advanceTo(30 * 1000);
expect(format(date, 'fa')).toEqual('۳۰ ثانیه پیش');
advanceTo(1000 * 60);
expect(format(date, 'fa')).toEqual('۱ دقیقه پیش');
advanceTo(1000 * 60 * 30);
expect(format(date, 'fa')).toEqual('۳۰ دقیقه پیش');
advanceTo(1000 * 60 * 60);
expect(format(date, 'fa')).toEqual('۱ ساعت پیش');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'fa')).toEqual('۸ ساعت پیش');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'fa')).toEqual('۱ روز پیش');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'fa')).toEqual('۳ روز پیش');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'fa')).toEqual('۱ هفته پیش');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'fa')).toEqual('۳ هفته پیش');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'fa')).toEqual('۱ ماه پیش');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'fa')).toEqual('۴ ماه پیش');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'fa')).toEqual('۱ سال پیش');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'fa')).toEqual('۱۰ سال پیش');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'fa')).toEqual('همین حالا');
advanceTo(-30 * 1000);
expect(format(date, 'fa')).toEqual('۳۰ ثانیه دیگر');
advanceTo(-1000 * 60);
expect(format(date, 'fa')).toEqual('۱ دقیقه دیگر');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'fa')).toEqual('۳۰ دقیقه دیگر');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'fa')).toEqual('۱ ساعت دیگر');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'fa')).toEqual('۸ ساعت دیگر');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'fa')).toEqual('۱ روز دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'fa')).toEqual('۳ روز دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'fa')).toEqual('۱ هفته دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'fa')).toEqual('۳ هفته دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'fa')).toEqual('۱ ماه دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'fa')).toEqual('۴ ماه دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'fa')).toEqual('۱ سال دیگر');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'fa')).toEqual('۱۰ سال دیگر');
});
});
timeago.js-4.0.2/__tests__/lang/he.spec.ts 0000664 0000000 0000000 00000010507 13577310712 0020342 0 ustar 00root root 0000000 0000000 import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import he from '../../src/lang/he';
register('he', he);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('he', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'he')).toEqual('זה עתה');
advanceTo(30 * 1000);
expect(format(date, 'he')).toEqual('לפני 30 שניות');
advanceTo(1000 * 60);
expect(format(date, 'he')).toEqual('לפני דקה');
advanceTo(1000 * 60 * 2);
expect(format(date, 'he')).toEqual('לפני 2 דקות');
advanceTo(1000 * 60 * 30);
expect(format(date, 'he')).toEqual('לפני 30 דקות');
advanceTo(1000 * 60 * 60);
expect(format(date, 'he')).toEqual('לפני שעה');
advanceTo(1000 * 60 * 60 * 2);
expect(format(date, 'he')).toEqual('לפני שעתיים');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'he')).toEqual('לפני 8 שעות');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'he')).toEqual('אתמול');
advanceTo(1000 * 60 * 60 * 24 * 2);
expect(format(date, 'he')).toEqual('לפני יומיים');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'he')).toEqual('לפני 3 ימים');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'he')).toEqual('לפני שבוע');
advanceTo(1000 * 60 * 60 * 24 * 7 * 2);
expect(format(date, 'he')).toEqual('לפני שבועיים');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'he')).toEqual('לפני 3 שבועות');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'he')).toEqual('לפני חודש');
advanceTo(1000 * 60 * 60 * 24 * 31 * 2);
expect(format(date, 'he')).toEqual('לפני חודשיים');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'he')).toEqual('לפני 4 חודשים');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'he')).toEqual('לפני שנה');
advanceTo(1000 * 60 * 60 * 24 * 366 * 2);
expect(format(date, 'he')).toEqual('לפני שנתיים');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'he')).toEqual('לפני 10 שנים');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'he')).toEqual('עכשיו');
advanceTo(-30 * 1000);
expect(format(date, 'he')).toEqual('בעוד 30 שניות');
advanceTo(-1000 * 60);
expect(format(date, 'he')).toEqual('בעוד דקה');
advanceTo(-1000 * 60 * 2);
expect(format(date, 'he')).toEqual('בעוד 2 דקות');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'he')).toEqual('בעוד 30 דקות');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'he')).toEqual('בעוד שעה');
advanceTo(-1000 * 60 * 60 * 2);
expect(format(date, 'he')).toEqual('בעוד שעתיים');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'he')).toEqual('בעוד 8 שעות');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'he')).toEqual('מחר');
advanceTo(-1000 * 60 * 60 * 24 * 2);
expect(format(date, 'he')).toEqual('בעוד יומיים');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'he')).toEqual('בעוד 3 ימים');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'he')).toEqual('בעוד שבוע');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 2);
expect(format(date, 'he')).toEqual('בעוד שבועיים');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'he')).toEqual('בעוד 3 שבועות');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'he')).toEqual('בעוד חודש');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 2);
expect(format(date, 'he')).toEqual('בעוד חודשיים');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'he')).toEqual('בעוד 4 חודשים');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'he')).toEqual('בעוד שנה');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 2);
expect(format(date, 'he')).toEqual('בעוד שנתיים');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'he')).toEqual('בעוד 10 שנים');
});
});
timeago.js-4.0.2/__tests__/lang/hi_IN.spec.ts 0000664 0000000 0000000 00000007121 13577310712 0020732 0 ustar 00root root 0000000 0000000 /**
* Created by porcus on 2018/10/09.
* Contact: avoicefromthedust@gmail.com
*/
import { advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import hi_IN from '../../src/lang/hi_IN';
register('hi_IN', hi_IN);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('hi_IN', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'hi_IN')).toEqual('अभी');
advanceTo(30 * 1000);
expect(format(date, 'hi_IN')).toEqual('30 सेकंड पहले');
advanceTo(1000 * 60);
expect(format(date, 'hi_IN')).toEqual('1 मिनट पहले');
advanceTo(1000 * 60 * 30);
expect(format(date, 'hi_IN')).toEqual('30 मिनट पहले');
advanceTo(1000 * 60 * 60);
expect(format(date, 'hi_IN')).toEqual('1 घंटे पहले');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'hi_IN')).toEqual('8 घंटे पहले');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'hi_IN')).toEqual('1 दिन पहले');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'hi_IN')).toEqual('3 दिन पहले');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'hi_IN')).toEqual('1 सप्ताह पहले');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'hi_IN')).toEqual('3 हफ्ते पहले');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'hi_IN')).toEqual('1 महीने पहले');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'hi_IN')).toEqual('4 महीने पहले');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'hi_IN')).toEqual('1 साल पहले');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'hi_IN')).toEqual('10 साल पहले');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'hi_IN')).toEqual('कुछ समय');
advanceTo(-30 * 1000);
expect(format(date, 'hi_IN')).toEqual('30 सेकंड में');
advanceTo(-1000 * 60);
expect(format(date, 'hi_IN')).toEqual('1 मिनट में');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'hi_IN')).toEqual('30 मिनट में');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'hi_IN')).toEqual('1 घंटे में');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'hi_IN')).toEqual('8 घंटे में');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'hi_IN')).toEqual('1 दिन में');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'hi_IN')).toEqual('3 दिनों में');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'hi_IN')).toEqual('1 सप्ताह में');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'hi_IN')).toEqual('3 हफ्तों में');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'hi_IN')).toEqual('1 महीने में');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'hi_IN')).toEqual('4 महीनों में');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'hi_IN')).toEqual('1 साल में');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'hi_IN')).toEqual('10 साल में');
});
});
timeago.js-4.0.2/__tests__/lang/index.spec.ts 0000664 0000000 0000000 00000000351 13577310712 0021051 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/24.
* Contact: i@hust.cc
*/
import * as langs from '../../src/lang';
describe('langs', () => {
test('locales shoule be in dict order', () => {
expect(typeof langs).toBe('object');
});
});
timeago.js-4.0.2/__tests__/lang/it.spec.ts 0000664 0000000 0000000 00000005636 13577310712 0020371 0 ustar 00root root 0000000 0000000 import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import it from '../../src/lang/it';
register('it', it);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('it', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'it')).toEqual('poco fa');
advanceTo(30 * 1000);
expect(format(date, 'it')).toEqual('30 secondi fa');
advanceTo(1000 * 60);
expect(format(date, 'it')).toEqual('un minuto fa');
advanceTo(1000 * 60 * 30);
expect(format(date, 'it')).toEqual('30 minuti fa');
advanceTo(1000 * 60 * 60);
expect(format(date, 'it')).toEqual("un'ora fa");
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'it')).toEqual('8 ore fa');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'it')).toEqual('un giorno fa');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'it')).toEqual('3 giorni fa');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'it')).toEqual('una settimana fa');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'it')).toEqual('3 settimane fa');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'it')).toEqual('un mese fa');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'it')).toEqual('4 mesi fa');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'it')).toEqual('un anno fa');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'it')).toEqual('10 anni fa');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'it')).toEqual('fra poco');
advanceTo(-30 * 1000);
expect(format(date, 'it')).toEqual('fra 30 secondi');
advanceTo(-1000 * 60);
expect(format(date, 'it')).toEqual('fra un minuto');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'it')).toEqual('fra 30 minuti');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'it')).toEqual("fra un'ora");
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'it')).toEqual('fra 8 ore');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'it')).toEqual('fra un giorno');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'it')).toEqual('fra 3 giorni');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'it')).toEqual('fra una settimana');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'it')).toEqual('fra 3 settimane');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'it')).toEqual('fra un mese');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'it')).toEqual('fra 4 mesi');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'it')).toEqual('fra un anno');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'it')).toEqual('fra 10 anni');
});
});
timeago.js-4.0.2/__tests__/lang/ka.spec.ts 0000664 0000000 0000000 00000006442 13577310712 0020344 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/24.
* Contact: i@hust.cc
*/
import { advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import ka from '../../src/lang/ka';
register('ka', ka);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('ka', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'ka')).toEqual('ამ წამს');
advanceTo(30 * 1000);
expect(format(date, 'ka')).toEqual('30 წამის წინ');
advanceTo(1000 * 60);
expect(format(date, 'ka')).toEqual('1 წუთის წინ');
advanceTo(1000 * 60 * 30);
expect(format(date, 'ka')).toEqual('30 წუთის წინ');
advanceTo(1000 * 60 * 60);
expect(format(date, 'ka')).toEqual('1 საათის წინ');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'ka')).toEqual('8 საათის წინ');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'ka')).toEqual('1 დღის წინ');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'ka')).toEqual('3 დღის წინ');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'ka')).toEqual('1 კვირის წინ');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'ka')).toEqual('3 კვირის წინ');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'ka')).toEqual('1 თვის წინ');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'ka')).toEqual('4 თვის წინ');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'ka')).toEqual('1 წლის წინ');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'ka')).toEqual('10 წლის წინ');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'ka')).toEqual('ახლა');
advanceTo(-30 * 1000);
expect(format(date, 'ka')).toEqual('30 წამში');
advanceTo(-1000 * 60);
expect(format(date, 'ka')).toEqual('1 წუთში');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'ka')).toEqual('30 წუთში');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'ka')).toEqual('1 საათში');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'ka')).toEqual('8 საათში');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'ka')).toEqual('1 დღეში');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'ka')).toEqual('3 დღეში');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'ka')).toEqual('1 კვირაში');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'ka')).toEqual('3 კვირაში');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'ka')).toEqual('1 თვეში');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'ka')).toEqual('4 თვეში');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'ka')).toEqual('1 წელიწადში');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'ka')).toEqual('10 წელიწადში');
});
});
timeago.js-4.0.2/__tests__/lang/nl.spec.ts 0000664 0000000 0000000 00000006052 13577310712 0020357 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/24.
* Contact: i@hust.cc
*/
import { advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import nl from '../../src/lang/nl';
register('nl', nl);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('nl', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'nl')).toEqual('recent');
advanceTo(30 * 1000);
expect(format(date, 'nl')).toEqual('30 seconden geleden');
advanceTo(1000 * 60);
expect(format(date, 'nl')).toEqual('1 minuut geleden');
advanceTo(1000 * 60 * 30);
expect(format(date, 'nl')).toEqual('30 minuten geleden');
advanceTo(1000 * 60 * 60);
expect(format(date, 'nl')).toEqual('1 uur geleden');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'nl')).toEqual('8 uur geleden');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'nl')).toEqual('1 dag geleden');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'nl')).toEqual('3 dagen geleden');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'nl')).toEqual('1 week geleden');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'nl')).toEqual('3 weken geleden');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'nl')).toEqual('1 maand geleden');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'nl')).toEqual('4 maanden geleden');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'nl')).toEqual('1 jaar geleden');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'nl')).toEqual('10 jaar geleden');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'nl')).toEqual('binnenkort');
advanceTo(-30 * 1000);
expect(format(date, 'nl')).toEqual('binnen 30 seconden');
advanceTo(-1000 * 60);
expect(format(date, 'nl')).toEqual('binnen 1 minuut');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'nl')).toEqual('binnen 30 minuten');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'nl')).toEqual('binnen 1 uur');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'nl')).toEqual('binnen 8 uur');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'nl')).toEqual('binnen 1 dag');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'nl')).toEqual('binnen 3 dagen');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'nl')).toEqual('binnen 1 week');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'nl')).toEqual('binnen 3 weken');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'nl')).toEqual('binnen 1 maand');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'nl')).toEqual('binnen 4 maanden');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'nl')).toEqual('binnen 1 jaar');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'nl')).toEqual('binnen 10 jaar');
});
});
timeago.js-4.0.2/__tests__/lang/oc.spec.ts 0000664 0000000 0000000 00000005706 13577310712 0020354 0 ustar 00root root 0000000 0000000 import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import oc from '../../src/lang/oc';
register('oc', oc);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('oc', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'oc')).toEqual('fa un moment');
advanceTo(30 * 1000);
expect(format(date, 'oc')).toEqual('fa 30 segondas');
advanceTo(1000 * 60);
expect(format(date, 'oc')).toEqual('fa 1 minuta');
advanceTo(1000 * 60 * 30);
expect(format(date, 'oc')).toEqual('fa 30 minutas');
advanceTo(1000 * 60 * 60);
expect(format(date, 'oc')).toEqual('fa 1 ora');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'oc')).toEqual('fa 8 oras');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'oc')).toEqual('fa 1 jorn');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'oc')).toEqual('fa 3 jorns');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'oc')).toEqual('fa 1 setmana');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'oc')).toEqual('fa 3 setmanas');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'oc')).toEqual('fa 1 mes');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'oc')).toEqual('fa 4 meses');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'oc')).toEqual('fa 1 an');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'oc')).toEqual('fa 10 ans');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'oc')).toEqual("d'aquí un moment");
advanceTo(-30 * 1000);
expect(format(date, 'oc')).toEqual("d'aquí 30 segondas");
advanceTo(-1000 * 60);
expect(format(date, 'oc')).toEqual("d'aquí 1 minuta");
advanceTo(-1000 * 60 * 30);
expect(format(date, 'oc')).toEqual("d'aquí 30 minutas");
advanceTo(-1000 * 60 * 60);
expect(format(date, 'oc')).toEqual("d'aquí 1 ora");
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'oc')).toEqual("d'aquí 8 oras");
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'oc')).toEqual("d'aquí 1 jorn");
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'oc')).toEqual("d'aquí 3 jorns");
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'oc')).toEqual("d'aquí 1 setmana");
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'oc')).toEqual("d'aquí 3 setmanas");
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'oc')).toEqual("d'aquí 1 mes");
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'oc')).toEqual("d'aquí 4 meses");
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'oc')).toEqual("d'aquí 1 an");
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'oc')).toEqual("d'aquí 10 ans");
});
});
timeago.js-4.0.2/__tests__/lang/pt_BR.spec.ts 0000664 0000000 0000000 00000006024 13577310712 0020753 0 ustar 00root root 0000000 0000000 import { advanceBy, advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import pt_BR from '../../src/lang/pt_BR';
register('pt_BR', pt_BR);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('Brazilian Portuguese', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'pt_BR')).toEqual('agora mesmo');
advanceTo(30 * 1000);
expect(format(date, 'pt_BR')).toEqual('há 30 segundos');
advanceTo(1000 * 60);
expect(format(date, 'pt_BR')).toEqual('há um minuto');
advanceTo(1000 * 60 * 30);
expect(format(date, 'pt_BR')).toEqual('há 30 minutos');
advanceTo(1000 * 60 * 60);
expect(format(date, 'pt_BR')).toEqual('há uma hora');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'pt_BR')).toEqual('há 8 horas');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'pt_BR')).toEqual('há um dia');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'pt_BR')).toEqual('há 3 dias');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'pt_BR')).toEqual('há uma semana');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'pt_BR')).toEqual('há 3 semanas');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'pt_BR')).toEqual('há um mês');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'pt_BR')).toEqual('há 4 meses');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'pt_BR')).toEqual('há um ano');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'pt_BR')).toEqual('há 10 anos');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'pt_BR')).toEqual('agora');
advanceTo(-30 * 1000);
expect(format(date, 'pt_BR')).toEqual('em 30 segundos');
advanceTo(-1000 * 60);
expect(format(date, 'pt_BR')).toEqual('em um minuto');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'pt_BR')).toEqual('em 30 minutos');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'pt_BR')).toEqual('em uma hora');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'pt_BR')).toEqual('em 8 horas');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'pt_BR')).toEqual('em um dia');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'pt_BR')).toEqual('em 3 dias');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'pt_BR')).toEqual('em uma semana');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'pt_BR')).toEqual('em 3 semanas');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'pt_BR')).toEqual('em um mês');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'pt_BR')).toEqual('em 4 meses');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'pt_BR')).toEqual('em um ano');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'pt_BR')).toEqual('em 10 anos');
});
});
timeago.js-4.0.2/__tests__/lang/ru.spec.ts 0000664 0000000 0000000 00000007642 13577310712 0020402 0 ustar 00root root 0000000 0000000 import { advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import ru from '../../src/lang/ru';
register('ru', ru);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('ru', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'ru')).toEqual('только что');
advanceTo(22 * 1000);
expect(format(date, 'ru')).toEqual('22 секунды назад');
advanceTo(30 * 1000);
expect(format(date, 'ru')).toEqual('30 секунд назад');
advanceTo(1000 * 60);
expect(format(date, 'ru')).toEqual('минуту назад');
advanceTo(1000 * 60 * 5);
expect(format(date, 'ru')).toEqual('5 минут назад');
advanceTo(1000 * 60 * 21);
expect(format(date, 'ru')).toEqual('21 минуту назад');
advanceTo(1000 * 60 * 22);
expect(format(date, 'ru')).toEqual('22 минуты назад');
advanceTo(1000 * 60 * 30);
expect(format(date, 'ru')).toEqual('30 минут назад');
advanceTo(1000 * 60 * 60);
expect(format(date, 'ru')).toEqual('час назад');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'ru')).toEqual('8 часов назад');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'ru')).toEqual('вчера');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'ru')).toEqual('3 дня назад');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'ru')).toEqual('неделю назад');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'ru')).toEqual('3 недели назад');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'ru')).toEqual('месяц назад');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'ru')).toEqual('4 месяца назад');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'ru')).toEqual('год назад');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'ru')).toEqual('10 лет назад');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'ru')).toEqual('через несколько секунд');
advanceTo(-30 * 1000);
expect(format(date, 'ru')).toEqual('через 30 секунд');
advanceTo(-1000 * 60);
expect(format(date, 'ru')).toEqual('через минуту');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'ru')).toEqual('через 30 минут');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'ru')).toEqual('через час');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'ru')).toEqual('через 8 часов');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'ru')).toEqual('завтра');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'ru')).toEqual('через 3 дня');
advanceTo(-1000 * 60 * 60 * 24 * 5);
expect(format(date, 'ru')).toEqual('через 5 дней');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'ru')).toEqual('через неделю');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'ru')).toEqual('через 3 недели');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'ru')).toEqual('через месяц');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'ru')).toEqual('через 4 месяца');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 5);
expect(format(date, 'ru')).toEqual('через 5 месяцев');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'ru')).toEqual('через год');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 2);
expect(format(date, 'ru')).toEqual('через 2 года');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'ru')).toEqual('через 10 лет');
});
});
timeago.js-4.0.2/__tests__/lang/zh_TW.spec.ts 0000664 0000000 0000000 00000006031 13577310712 0020776 0 ustar 00root root 0000000 0000000 /**
* Created by leoliu1209 on 18/12/11.
* Contact: cubemail88@gmail.com
*/
import { advanceTo, clear } from 'jest-date-mock';
import { register, format } from '../../src';
import zh_TW from '../../src/lang/zh_TW';
register('zh_TW', zh_TW);
let date = new Date();
beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('zh_TW', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'zh_TW')).toEqual('剛剛');
advanceTo(30 * 1000);
expect(format(date, 'zh_TW')).toEqual('30 秒前');
advanceTo(1000 * 60);
expect(format(date, 'zh_TW')).toEqual('1 分鐘前');
advanceTo(1000 * 60 * 30);
expect(format(date, 'zh_TW')).toEqual('30 分鐘前');
advanceTo(1000 * 60 * 60);
expect(format(date, 'zh_TW')).toEqual('1 小時前');
advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'zh_TW')).toEqual('8 小時前');
advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'zh_TW')).toEqual('1 天前');
advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'zh_TW')).toEqual('3 天前');
advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'zh_TW')).toEqual('1 週前');
advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'zh_TW')).toEqual('3 週前');
advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'zh_TW')).toEqual('1 個月前');
advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'zh_TW')).toEqual('4 個月前');
advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'zh_TW')).toEqual('1 年前');
advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'zh_TW')).toEqual('10 年前');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'zh_TW')).toEqual('片刻後');
advanceTo(-30 * 1000);
expect(format(date, 'zh_TW')).toEqual('30 秒後');
advanceTo(-1000 * 60);
expect(format(date, 'zh_TW')).toEqual('1 分鐘後');
advanceTo(-1000 * 60 * 30);
expect(format(date, 'zh_TW')).toEqual('30 分鐘後');
advanceTo(-1000 * 60 * 60);
expect(format(date, 'zh_TW')).toEqual('1 小時後');
advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'zh_TW')).toEqual('8 小時後');
advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'zh_TW')).toEqual('1 天後');
advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'zh_TW')).toEqual('3 天後');
advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'zh_TW')).toEqual('1 週後');
advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'zh_TW')).toEqual('3 週後');
advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'zh_TW')).toEqual('1 個月後');
advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'zh_TW')).toEqual('4 個月後');
advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'zh_TW')).toEqual('1 年後');
advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'zh_TW')).toEqual('10 年後');
});
});
timeago.js-4.0.2/__tests__/realtime.spec.ts 0000664 0000000 0000000 00000001476 13577310712 0020634 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { render, cancel } from '../src/';
import { createTimeNode, delay } from './helper';
const now = +new Date();
const time1 = createTimeNode();
const time2 = createTimeNode();
time1.setAttribute('datetime', now - 15000 + '');
time2.setAttribute('datetime', now - 20000 + '');
describe('realtime', () => {
test('render', async () => {
render(time1, 'en_US');
render(time2, 'zh_CN');
await delay(2500);
expect(time1.innerText).toBe('17 seconds ago');
expect(time2.innerText).toBe('22 秒前');
});
test('cancel', async () => {
// cancel one
cancel(time1);
// cancel all
cancel();
await delay(2500);
expect(time1.innerText).toBe('17 seconds ago');
expect(time2.innerText).toBe('22 秒前');
});
});
timeago.js-4.0.2/__tests__/register.spec.ts 0000664 0000000 0000000 00000000655 13577310712 0020654 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { getLocale, register } from '../src/register';
describe('register', () => {
test('register', () => {
const test = (diff: number, idx: number, totalSec: number) => ['test', 'locale'] as [string, string];
register('test', test);
expect(getLocale('test')).toBe(test);
expect(getLocale('test')(1, 1)).toEqual(['test', 'locale']);
});
});
timeago.js-4.0.2/__tests__/utils/ 0000775 0000000 0000000 00000000000 13577310712 0016661 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/__tests__/utils/date.spec.ts 0000664 0000000 0000000 00000003505 13577310712 0021102 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { toDate, formatDiff, diffSec, nextInterval } from '../../src/utils/date';
import { register, getLocale } from '../../src/register';
import en_US from '../../src/lang/en_US';
import zh_CN from '../../src/lang/zh_CN';
register('en_US', en_US);
register('zh_CN', zh_CN);
describe('date', () => {
test('toTimestamp', () => {
expect(toDate('1992-08-01')).toBeInstanceOf(Date);
expect(toDate(712627200000)).toBeInstanceOf(Date);
expect(toDate('2017-2-5 3:57:52UTC')).toBeInstanceOf(Date);
expect(toDate('2017-2-5T3:57:52Z')).toBeInstanceOf(Date);
expect(toDate()).toBeInstanceOf(Date);
});
test('formatDiff', () => {
expect(formatDiff(100, getLocale('en'))).toEqual('1 minute ago');
expect(formatDiff(-1000, getLocale('en'))).toEqual('in 16 minutes');
expect(formatDiff(-1000, getLocale('en'))).toEqual('in 16 minutes');
expect(formatDiff(-1000, getLocale('not-exist-locale'))).toEqual('in 16 minutes');
expect(formatDiff(-1000, getLocale('not-exist-locale'))).toEqual('in 16 minutes');
/**
* Big number test
*/
expect(formatDiff(-9999999999999999999999, getLocale('en'))).toEqual('in 317097919837645 years');
});
test('diffSec', () => {
const now = new Date();
// @ts-ignore
expect(diffSec(now)).toBeApproximate(0);
// @ts-ignore
expect(diffSec(now, now)).toBeApproximate(0);
// @ts-ignore
expect(diffSec(new Date(+now - 10000), now)).toBeApproximate(10);
});
test('nextInterval', () => {
expect(nextInterval(1)).toEqual(1); // sec
expect(nextInterval(30)).toEqual(1); // sec
expect(nextInterval(110)).toEqual(10); // minute
expect(nextInterval(2 * 3600 + 100)).toEqual(3500); // hour
expect(nextInterval(3600 * 24 + 3600)).toEqual(23 * 3600); // day
});
});
timeago.js-4.0.2/__tests__/utils/dom.spec.ts 0000664 0000000 0000000 00000001025 13577310712 0020737 0 ustar 00root root 0000000 0000000 /**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/
import { getTimerId, getDateAttribute, setTimerId } from '../../src/utils/dom';
import { createTimeNode } from '../helper';
const ms = +new Date();
const time = createTimeNode(ms);
describe('dom', () => {
test('timer id', () => {
setTimerId(time, 123);
expect(getTimerId(time)).toEqual(123);
// @ts-ignore
expect(() => getTimerId()).toThrow();
});
test('getDateAttribute', () => {
expect(getDateAttribute(time)).toBe(`${ms}`);
});
});
timeago.js-4.0.2/bower.json 0000664 0000000 0000000 00000001016 13577310712 0015572 0 ustar 00root root 0000000 0000000 {
"name": "timeago.js",
"description": "timeago.js is a simple library (only 1kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'. localization supported.",
"main": "dist/timeago.min.js",
"authors": [
"Hustcc "
],
"license": "MIT",
"keywords": [
"timeago",
"datetime",
"*** time ago",
"date",
"javascript timeago"
],
"homepage": "https://github.com/hustcc/timeago.js",
"ignore": [
"**/.*",
"node_modules",
"bower_components"
]
}
timeago.js-4.0.2/gh-pages/ 0000775 0000000 0000000 00000000000 13577310712 0015256 5 ustar 00root root 0000000 0000000 timeago.js-4.0.2/gh-pages/CNAME 0000664 0000000 0000000 00000000013 13577310712 0016016 0 ustar 00root root 0000000 0000000 timeago.org timeago.js-4.0.2/gh-pages/clock.png 0000664 0000000 0000000 00000014014 13577310712 0017057 0 ustar 00root root 0000000 0000000 PNG
IHDR >a sBIT|d pHYs IDATx{|dUkJRIwݤ$gݐD5(S8aTa+^/ G#f:muUIZG*}TUSɩ:OUks
u|v8D)" ̣ MUFD>ECDYD!ԐRpX<%#."'0s `5ߨʩP#Ǚi BIfj[ 1gE<_DDt8/
`[<_?22ؾr:;;(8λT}j2s'&b-a}].iH&1Ug8wFV___S]Dt'ҩ7s Rr|#+ DTufCDYD"