pax_global_header00006660000000000000000000000064135773107120014520gustar00rootroot0000000000000052 comment=bb55152bd64a5635500e36fb0c32c66fbacae140 timeago.js-4.0.2/000077500000000000000000000000001357731071200135635ustar00rootroot00000000000000timeago.js-4.0.2/.commitlintrc.js000066400000000000000000000003061357731071200167020ustar00rootroot00000000000000module.exports = { rules: { 'type-enum': [ 2, 'always', ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test', 'wip'], ], }, }; timeago.js-4.0.2/.eslintrc000066400000000000000000000006631357731071200154140ustar00rootroot00000000000000{ "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/000077500000000000000000000000001357731071200151235ustar00rootroot00000000000000timeago.js-4.0.2/.github/FUNDING.yml000066400000000000000000000012611357731071200167400ustar00rootroot00000000000000# 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/000077500000000000000000000000001357731071200171605ustar00rootroot00000000000000timeago.js-4.0.2/.github/workflows/build.yml000066400000000000000000000011231357731071200207770ustar00rootroot00000000000000name: 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.yml000066400000000000000000000004571357731071200211520ustar00rootroot00000000000000on: 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.yml000066400000000000000000000024451357731071200213300ustar00rootroot00000000000000name: 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/.gitignore000066400000000000000000000001541357731071200155530ustar00rootroot00000000000000node_modules/ npm-debug.* .idea coverage package-lock.json lib esm dist timeago.full.min.js timeago.min.js timeago.js-4.0.2/.prettierrc000066400000000000000000000002161357731071200157460ustar00rootroot00000000000000{ "semi": true, "singleQuote": true, "trailingComma": "all", "bracketSpacing": true, "printWidth": 120, "arrowParens": "always" } timeago.js-4.0.2/LICENSE000066400000000000000000000020611357731071200145670ustar00rootroot00000000000000The 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.md000066400000000000000000000117321357731071200150460ustar00rootroot00000000000000# 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). [![npm Version](https://img.shields.io/npm/v/timeago.js.svg)](https://www.npmjs.com/package/timeago.js) [![unpkg](https://img.shields.io/npm/v/timeago.js?label=cdn)](https://unpkg.com/browse/timeago.js/) [![Build Status](https://github.com/hustcc/timeago.js/workflows/build/badge.svg)](https://github.com/hustcc/timeago.js/actions) [![Coverage Status](https://coveralls.io/repos/github/hustcc/timeago.js/badge.svg?branch=master)](https://coveralls.io/github/hustcc/timeago.js?branch=master) [![Dist gzip](https://img.badgesize.io/https://unpkg.com/timeago.js/dist/timeago.min.js?compression=gzip)](https://unpkg.com/timeago.js/dist/timeago.min.js) [![npm Download](https://img.shields.io/npm/dm/timeago.js.svg)](https://www.npmjs.com/package/timeago.js) [![npm License](https://img.shields.io/npm/l/timeago.js.svg)](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__/000077500000000000000000000000001357731071200155215ustar00rootroot00000000000000timeago.js-4.0.2/__tests__/format.spec.ts000066400000000000000000000011231357731071200203070ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000011421357731071200177620ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000007031357731071200173500ustar00rootroot00000000000000/** * 创建一个 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.ts000066400000000000000000000057401357731071200201370ustar00rootroot00000000000000/** * 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/000077500000000000000000000000001357731071200164425ustar00rootroot00000000000000timeago.js-4.0.2/__tests__/lang/cs.spec.ts000066400000000000000000000113141357731071200203500ustar00rootroot00000000000000import { 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.ts000066400000000000000000000061601357731071200203340ustar00rootroot00000000000000import { 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.ts000066400000000000000000000105071357731071200203420ustar00rootroot00000000000000import { 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.ts000066400000000000000000000071211357731071200207320ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000003511357731071200210510ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000056361357731071200203710ustar00rootroot00000000000000import { 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.ts000066400000000000000000000064421357731071200203440ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000060521357731071200203570ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000057061357731071200203540ustar00rootroot00000000000000import { 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.ts000066400000000000000000000060241357731071200207530ustar00rootroot00000000000000import { 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.ts000066400000000000000000000076421357731071200204020ustar00rootroot00000000000000import { 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.ts000066400000000000000000000060311357731071200207760ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000014761357731071200206340ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000006551357731071200206540ustar00rootroot00000000000000/** * 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/000077500000000000000000000000001357731071200166615ustar00rootroot00000000000000timeago.js-4.0.2/__tests__/utils/date.spec.ts000066400000000000000000000035051357731071200211020ustar00rootroot00000000000000/** * 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.ts000066400000000000000000000010251357731071200207370ustar00rootroot00000000000000/** * 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.json000066400000000000000000000010161357731071200155720ustar00rootroot00000000000000{ "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/000077500000000000000000000000001357731071200152565ustar00rootroot00000000000000timeago.js-4.0.2/gh-pages/CNAME000066400000000000000000000000131357731071200160160ustar00rootroot00000000000000timeago.orgtimeago.js-4.0.2/gh-pages/clock.png000066400000000000000000000140141357731071200170570ustar00rootroot00000000000000PNG  IHDR>asBIT|d pHYs  IDATx{|dUkJRIwݤ$gݐD5(S8aTa+ ^/ G #f:muUIZG*}TUSɩ:OUks u|v8D)"̣MUFD>ECDYD!ԐRpX<%#."'0s`5ߨʩP#ǙiBIfj[1gE<_DDt8/ `[<_?22ؾr:;;(8λT}j2s'& b -a}].iH&1Ug8wFV___S]Dt'ҩ7sRr|#+DTufCDY  D"=\PσW-1#+A efR6}s,@D>_N}ۛ# "c$rotD"X yL|]|yy!|oڠ%"1::oܸJ>666+kYkfc4".rWr9oe8S6j"2+Wʳ;}Oay^J&F`@"x,""sZUem.U-WI2 Dt~yuj_-fR"򿈨ED# <[Q^ B5":kҥ lvc(z33?i9WYcdr4D" j0`"_DRTQQ:<2U]O$1f0uݎ/(<+CCCoB)̧1ѱXwxN3߷e˖ [[[b t-toz{{1f^ G\J:ö~Q@DU:n/Ydd2)߱y7UDst͛op>@1)k/^x<[hQK4|4=OU?̧Y|ka2XGGGEy/`W f\=>C7n&Q3---oٲem1ζjh={1;\Y=E"=PPnjjZ4l6\. vf7}'TDZl6rx<Edɒ%K޴iH,lhh8v޼yX Ba|?cD Bgfقx~;<"H<{}zk{{{s]+=1uD1cW'x ) L4ێ@D9Dth Dtݕ1f=쳻 1>>~$"c k֬IOD)˝hpp `bHDnžέ ZkϩOP}N|\>[h}SUo֞a0s3ی1iMDt6dժU|GGGpg{{SzQN`kkCs֭[_jmmSO mft5CP~ V~_lڴomm* k]uH$EdBDtt6onn3wI&19GU{\._7H@ӵWZ>5umwsi=u t]7 :[U[-zzzڬ7ck24eU Qǖn}x<~%644=<IDj3_U(nm۶x\cضBR5^t:=+1,U-e1Wtww/8XIDKYި$01#>*jjI{{{sšs#3trPU򻫩Y.M"r>ygSTC=4K$SS]H55_`ez=fj,;:c&OUy3Z5oGǪ)_$,j't8W^y_T ~6.5Ꝺ\7FDN-J?ꑵ(+a\./֚*_q #ȠEd2=恉y Uy?cuzܕ矮Uyޣu y y#h!U2! MD3sj```{:L&Sis9H$"DO_L"j$9]m_0r֚ W93222rd"8S| Ƙ1"GUorۓa?|AzjzUL&SUE50U=ZkMi3ZK\o?}TPÉ\.yGDzU]dwAbU BQ^= Ǻѧy!T5DDkTWUeUm1H|TUSr_\IDmCl)H$',o{w+^"* .\Ԏի783MDj̼@DoZiU*MF^X1+Nv6h9Dtc"x%bq8s3 qn4n~WWW8 ?8FU y# y D4 `Ef^\,7UF ZViQ~[U^WnZkDnfvUMMMZjh:|UKdh%UADpxm* ر' Ri{CCVL$)0VLd";wa6lJJDP5\. kmNDnywss'{ {ID~ .[jմo`e>nF1aL$BccH:QSa}_9 ծظNDb c;v8bn֞QZl+ajǹl_Dc̙"209]U* ;#'"o@U5|\.DdxƈLӵ'iǎ'ZkWyD|> ToJ|D8^\FEbM]+8Czt'Û]v]"0sDt8}KDѫ.rUD"qw.D>L0aU}a…{:cWBv{zz;;;0S@ƘwcίpzzzvoZkWXkuݎ:ԭXk?W1-tV15#`@U^˖-W,/UsTk~x* Zo300=;GE"\jnk׮͈6]{+J%#xO# DW(":i1(E)Tk27ߋH]r&cܯޜNU.P,'={cΨ\$JE*;ԜuD䗕\\.g2Cn+k $?,dr%X7hhh\L& qU^u3J1sp]7nh"8ky 8Ȼ66K9rT"rv27{"=>/OcU,onݓDywGegsǹDnguFq]bnѿq]7ND7cݺu A;Pf"K`5uztwR.WկB=ϻwj|>U++*ސG:::oR86U܋v+<ͣm^܄BEUk>[/49H;DYk߳?_랤JDfd8V(v̟?M"j֭ /w1bRJs,a B;?aÆH$R"^:AKPإc BOу1TR~nw+2"y;z3y.ijjކ7D\@Dѥvɋxc/սf֯_?JDLDKDd2{ Bqy ־'>nSn&H,8/LLz""JŌ<U*32d27 DA 镄 J2t҅REӼ Q |AU?oRTڙغ] of~  L@~\ ^ Uufw-X Ǐ/JY'bƷ|>Ey5b*y޵͟?A5h45\MDeo&k?5n#Lil~50Pk筵劃iXZڎfw,]t6c8fE 0I&y"]D>fY\M "zڝrx5\ww.;{TCZkP-f@.[ID "z*6QY30UߑL&cڣ|[U/r+yRu"bj=*~"YL{c$|>-gY~L4|qK^" '(ܠFuO}!s/>O!fuh_(~~d3}~FGFF8%-BWh42Z.%vnٲeˬ^7+C*_,بk!u?g1pqBL&L&26L#'@"xވp^+˟ Ü1ISrOTrf^gP4H:~cc5S;12Oe@2/%"D|yڵkY4 Ŏ-\5rUz-3HE"j#W,\z惔jUULL-yH$N}>3EDt9ϰJDU7]KY]]]]vU"8|60sccc/{ZV2]HR}?\UwWV(Ǚr688裏|ߏH33P(9ɬ{T*5hpGGGhѢ J/0IIENDB`timeago.js-4.0.2/gh-pages/css.css000066400000000000000000000027011357731071200165600ustar00rootroot00000000000000* { margin: 0; padding: 0; } html {background-color: #ccc;} body { font-family: Helvetica,Arial,sans-serif; color: #333; font-size: 16px; line-height: 24px; padding: 24px; max-width:750px; margin: 0 auto; border: 1px solid #999; border-width: 0 1px 1px 1px; background-color:#fff;} h1 { margin: 0; font-size: 50px; line-height: 100px; text-align: center; } h2 { margin: -30px 0 40px 50px; font-size: 20px; line-height: 20px; text-align: center; color: #999; } h3 { margin: 24px 0 6px 0; font-size: 18px; line-height: 18px; border-bottom: 1px solid #ccc; } h1 img { vertical-align: middle; } p { margin: 0 0 24px 0; } p.example { margin: 0 0 12px 0; } p.how, p.last { margin: 0; } ul { margin: 0 24px 24px; } li { line-height: 24px; } pre { background-color: #3a3a3d; color: #fff; margin: 12px 0; font-size: 12px; padding: 0 6px; word-break:break-all; white-space: pre-wrap; } pre em { font-style: normal; background-color: #554; } pre, tt { font-family: monaco, "courier new", mono, monospace; } abbr[title], time[title] { border-bottom: 1px dotted #333; } tt { font-size: 14px; } a { color: #06e; padding: 1px; } em { font-style: normal; background-color: #feb; } a:hover { background-color: #06c; color: #fff; text-decoration: none; } #content { margin:0 auto; width: 100%; border-bottom: 1px solid #999;} #footer { margin:0 auto 24px; padding: 12px; max-width:750px; width: 100%; line-height: 24px; } .help { font-size: 14px; color: #888; } .strong {font-weight: bold;}timeago.js-4.0.2/gh-pages/demo.html000066400000000000000000000077331357731071200171020ustar00rootroot00000000000000 timeago.js: testcases.

timeago.js

        a tiny / simple library

What ?

timeago.js is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependency. and support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). Download, view the examples, and enjoy.

Test for native DOM

You opened this page

You opened this page .

Test for Locales ?

You opened this page .

Test refreshing with minimal interval (every 3 second update) ?

You opened this page .

timeago.js-4.0.2/gh-pages/index.html000066400000000000000000000153641357731071200172640ustar00rootroot00000000000000 timeago.js: is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependency.

timeago.js

        a tiny / simple library

What ?

timeago.js is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependency. and support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). Download, view the examples, and enjoy.

You opened this page . (This will update automatically. Wait for it.)

Hustcc was born Aug 01, 1989.

Why ?

timeago.js was built to format date with `*** time ago` statement. You can test timeago.js here with the live demo.

  • Avoid timestamps dated "1 minute ago" even though the page was opened 10 minutes ago; timeago refreshes automatically.
  • You can take full advantage of page caching in your web applications, because the timestamps aren't calculated on the server.
  • Very tiny(less than 2kb), and has no dependency, e.g. jQuery.

How ?

First, load and install timeago.js library:

npm install timeago.js

Load timeago.js library file with script tag:

<script src="dist/timeago.js" type="text/javascript"></script>

Or you can use ES6 style:

import * as timeago from 'timeago.js';

Now, let's attach it to your timestamps on DOM ready:

timeago().render(document.querySelectorAll('.need_to_be_rendered'));

This will realtime render all selected(javascript DOM selector) elements with a class of need_to_be_rendered.

<span class="need_to_be_rendered" datetime="2016-07-07T09:24:17Z">July 07, 2016</span>

You can also use it programmatically:

timeago.format(new Date());             //=> ""
timeago.format('2016-09-07', 'zh_CN')           //=> ""
timeago.format(1473245023718);          //=> ""

Locales register ?

Yes, timeago.js has locale/i18n/language support. Here are some configuration examples. Please submit a GitHub pull request for corrections or additional languages.

var locale = function(number, index, totalSec) {
  // number: the time ago / time in 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];
};
timeago.register('pt_BR', locale);
// then you can use it
timeago.format(1473245023718, 'pt_BR');

Where ?

Package is managed with npm. so npm install timeago.js will be the latest version.

The code is hosted on GitHub: http://github.com/hustcc/timeago.js. Go on, live on the edge.

Who ?

timeago.js was built by Hustcc while standing on the shoulders of giants.

What else ?

  • timeago.js for react: timeago-react is here
  • timeago for python: timeago is here

Other timeago, welcome to pull a request.

Do you use timeago.js ?

Great! Please let me know, and can add into the README.

timeago.js-4.0.2/gh-pages/index.js000066400000000000000000000024271357731071200167300ustar00rootroot00000000000000function iso8601(date) { return date.getUTCFullYear() + "-" + (date.getUTCMonth()+1) + "-" + date.getUTCDate() + "T" + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds() + "Z"; } function init_index_page() { document.querySelector('.load_time').setAttribute('datetime', iso8601(new Date())); var locale = navigator.language.replace('-', '_'); timeago.render(document.querySelectorAll('.need_to_be_rendered'), locale); // 2. demo document.getElementById('demo_now').innerHTML = timeago.format(new Date()); document.getElementById('demo_20160907').innerHTML = timeago.format('2016-09-07'); document.getElementById('demo_timestamp').innerHTML = timeago.format(1473245023718); } function init_test_page() { document.querySelectorAll('.native time').forEach(function(node) { node.setAttribute('datetime', iso8601(new Date())); }); document.querySelectorAll('.native time').forEach(function(node) { node.setAttribute('datetime', iso8601(new Date())); }); document.querySelectorAll('.locales time').forEach(function(node) { node.setAttribute('datetime', iso8601(new Date())); }); document.querySelectorAll('.min-interval time').forEach(function(node) { node.setAttribute('datetime', iso8601(new Date())); }); } timeago.js-4.0.2/package.json000066400000000000000000000056751357731071200160660ustar00rootroot00000000000000{ "name": "timeago.js", "officialName": "timeago.js", "version": "4.0.2", "summary": "timeago.js is a simple library (less than 1kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'.", "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": "lib/index.js", "module": "esm/index.js", "files": [ "lib", "esm", "dist" ], "scripts": { "lint": "eslint src/**/* __tests__/**/*", "lint-staged": "lint-staged", "size": "size-limit", "test": "jest", "ci": "npm run lint && npm run test && npm run size && lint-md .", "build:umd": "rimraf ./dist && rollup -c && cp -rf dist/ gh-pages && npm run size", "build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib", "build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm", "build": "npm run build:cjs && npm run build:esm && npm run build:umd", "prepublishOnly": "npm run build" }, "dependencies": {}, "devDependencies": { "@commitlint/cli": "^8.2.0", "@types/jest": "^24.0.18", "@typescript-eslint/eslint-plugin": "^2.3.1", "@typescript-eslint/parser": "^2.3.1", "cross-env": "^5.1.3", "eslint": "^6.4.0", "eslint-config-prettier": "^6.3.0", "husky": "^3.0.5", "jest": "^24.9.0", "jest-date-mock": "^1.0.5", "jest-electron": "^0.1.7", "jest-expect": "^0.0.1", "lint-md-cli": "^0.1.0", "lint-staged": "^9.3.0", "prettier": "^1.18.2", "rimraf": "^3.0.0", "rollup": "^1.23.1", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-typescript": "^1.0.1", "rollup-plugin-uglify": "^6.0.3", "size-limit": "^0.18.0", "ts-jest": "^24.1.0", "typescript": "^3.6.3" }, "size-limit": [ { "limit": "1 KB", "path": "dist/timeago.min.js" }, { "limit": "10 KB", "path": "dist/timeago.full.min.js" } ], "jest": { "preset": "ts-jest", "runner": "jest-electron/runner", "testEnvironment": "jest-electron/environment", "setupFilesAfterEnv": [ "jest-expect" ], "testRegex": "(/__tests__/.*(test|spec))\\.ts$", "testURL": "https://timeago.org", "collectCoverage": true, "collectCoverageFrom": [ "src/**/*.ts", "!**/node_modules/**" ] }, "lint-staged": { "*.{ts,tsx}": [ "eslint --fix", "prettier --write", "git add" ] }, "husky": { "hooks": { "pre-commit": "npm run lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, "author": { "name": "hustcc", "url": "https://timeago.org" }, "license": "MIT", "keywords": [ "timeago", "datetime", "*** time ago", "date", "javascript timeago" ], "repository": { "type": "git", "url": "https://github.com/hustcc/timeago.js" }, "bugs": { "url": "https://github.com/hustcc/timeago.js/issues" } } timeago.js-4.0.2/rollup.config.js000066400000000000000000000012261357731071200167030ustar00rootroot00000000000000/** * Created by hustcc on 18/5/20. * Contract: i@hust.cc */ import { uglify } from 'rollup-plugin-uglify'; import resolve from 'rollup-plugin-node-resolve'; import typescript from 'rollup-plugin-typescript'; module.exports = [ { input: 'src/index.ts', output: { file: 'dist/timeago.min.js', name: 'timeago', format: 'umd', }, plugins: [ resolve(), typescript(), uglify(), ], }, { input: 'src/full.ts', output: { file: 'dist/timeago.full.min.js', name: 'timeago', format: 'umd', }, plugins: [ resolve(), typescript(), uglify(), ], }, ]; timeago.js-4.0.2/src/000077500000000000000000000000001357731071200143525ustar00rootroot00000000000000timeago.js-4.0.2/src/format.ts000066400000000000000000000007011357731071200162100ustar00rootroot00000000000000import { formatDiff, diffSec } from './utils/date'; import { getLocale } from './register'; import { Opts, TDate } from './interface'; /** * format a TDate into string * @param date * @param locale * @param opts */ export const format = (date: TDate, locale?: string, opts?: Opts): string => { // diff seconds const sec = diffSec(date, opts && opts.relativeDate); // format it with locale return formatDiff(sec, getLocale(locale)); }; timeago.js-4.0.2/src/full.ts000066400000000000000000000005101357731071200156600ustar00rootroot00000000000000/** * Created by hustcc on 18/5/20. * Contract: i@hust.cc */ import { format, render, cancel, register } from '.'; import * as Languages from './lang'; Object.keys(Languages).forEach((locale: string) => { register(locale, Languages[locale]); }); export { format, render, cancel, register }; export * from './interface'; timeago.js-4.0.2/src/index.ts000066400000000000000000000005451357731071200160350ustar00rootroot00000000000000/** * Created by hustcc on 18/5/20. * Contract: i@hust.cc */ import en_US from './lang/en_US'; import zh_CN from './lang/zh_CN'; import { register } from './register'; register('en_US', en_US); register('zh_CN', zh_CN); export { format } from './format'; export { render, cancel } from './realtime'; export { register }; export * from './interface'; timeago.js-4.0.2/src/interface.ts000066400000000000000000000006371357731071200166700ustar00rootroot00000000000000export type LocaleFunc = (diff: number, idx: number, totalSec?: number) => [string, string]; export type LocaleMap = Record; export type TDate = Date | string | number; export type TimerPool = Record; /** * render / format options */ export type Opts = { /** the relative date */ readonly relativeDate?: TDate; /** the realtime */ readonly minInterval?: number; }; timeago.js-4.0.2/src/lang/000077500000000000000000000000001357731071200152735ustar00rootroot00000000000000timeago.js-4.0.2/src/lang/ar.ts000066400000000000000000000017701357731071200162520ustar00rootroot00000000000000const timeTypes = [ ['ثانية', 'ثانيتين', '%s ثوان', '%s ثانية'], // Seconds ['دقيقة', 'دقيقتين', '%s دقائق', '%s دقيقة'], // Minutes ['ساعة', 'ساعتين', '%s ساعات', '%s ساعة'], // Hours ['يوم', 'يومين', '%s أيام', '%s يوماً'], // Days ['أسبوع', 'أسبوعين', '%s أسابيع', '%s أسبوعاً'], // Weeks ['شهر', 'شهرين', '%s أشهر', '%s شهراً'], // Months ['عام', 'عامين', '%s أعوام', '%s عاماً'], // Years ]; function formatTime(type: number, n: number): string { if (n < 3) return timeTypes[type][n - 1]; if (n >= 3 && n <= 10) return timeTypes[type][2]; return timeTypes[type][3]; } export default function(number: number, index: number): [string, string] { if (index === 0) { return ['منذ لحظات', 'بعد لحظات']; } const timeStr = formatTime(Math.floor(index / 2), number); return ['منذ' + ' ' + timeStr, 'بعد' + ' ' + timeStr]; } timeago.js-4.0.2/src/lang/be.ts000066400000000000000000000040351357731071200162330ustar00rootroot00000000000000/** * * @param f1 - 1 * @param f - 21, 31, ... * @param s - 2-4, 22-24, 32-34 ... * @param t - 5-20, 25-30, ... * @param n * @returns */ function formatNum(f1: string, f: string, s: string, t: string, n: number): string { const n10 = n % 10; let str = t; if (n === 1) { str = f1; } else if (n10 === 1 && n > 20) { str = f; } else if (n10 > 1 && n10 < 5 && (n > 20 || n < 10)) { str = s; } return str; } const seconds = formatNum.bind(null, 'секунду', '%s секунду', '%s секунды', '%s секунд'), minutes = formatNum.bind(null, 'хвіліну', '%s хвіліну', '%s хвіліны', '%s хвілін'), hours = formatNum.bind(null, 'гадзіну', '%s гадзіну', '%s гадзіны', '%s гадзін'), days = formatNum.bind(null, 'дзень', '%s дзень', '%s дні', '%s дзён'), weeks = formatNum.bind(null, 'тыдзень', '%s тыдзень', '%s тыдні', '%s тыдняў'), months = formatNum.bind(null, 'месяц', '%s месяц', '%s месяцы', '%s месяцаў'), years = formatNum.bind(null, 'год', '%s год', '%s гады', '%s гадоў'); export default function(number: number, index: number): [string, string] { switch (index) { case 0: return ['толькі што', 'праз некалькі секунд']; case 1: return [seconds(number) + ' таму', 'праз ' + seconds(number)]; case 2: case 3: return [minutes(number) + ' таму', 'праз ' + minutes(number)]; case 4: case 5: return [hours(number) + ' таму', 'праз ' + hours(number)]; case 6: case 7: return [days(number) + ' таму', 'праз ' + days(number)]; case 8: case 9: return [weeks(number) + ' таму', 'праз ' + weeks(number)]; case 10: case 11: return [months(number) + ' таму', 'праз ' + months(number)]; case 12: case 13: return [years(number) + ' таму', 'праз ' + years(number)]; default: return ['', '']; } } timeago.js-4.0.2/src/lang/bg.ts000066400000000000000000000016721357731071200162410ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['току що', 'съвсем скоро'], ['преди %s секунди', 'след %s секунди'], ['преди 1 минута', 'след 1 минута'], ['преди %s минути', 'след %s минути'], ['преди 1 час', 'след 1 час'], ['преди %s часа', 'след %s часа'], ['преди 1 ден', 'след 1 ден'], ['преди %s дни', 'след %s дни'], ['преди 1 седмица', 'след 1 седмица'], ['преди %s седмици', 'след %s седмици'], ['преди 1 месец', 'след 1 месец'], ['преди %s месеца', 'след %s месеца'], ['преди 1 година', 'след 1 година'], ['преди %s години', 'след %s години'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/bn_IN.ts000066400000000000000000000021751357731071200166350ustar00rootroot00000000000000// Bangla (India) export default function(number: number, index: number): [string, string] { return [ ['এইমাত্র', 'একটা সময়'], ['%s সেকেন্ড আগে', '%s এর সেকেন্ডের মধ্যে'], ['1 মিনিট আগে', '1 মিনিটে'], ['%s এর মিনিট আগে', '%s এর মিনিটের মধ্যে'], ['1 ঘন্টা আগে', '1 ঘন্টা'], ['%s ঘণ্টা আগে', '%s এর ঘন্টার মধ্যে'], ['1 দিন আগে', '1 দিনের মধ্যে'], ['%s এর দিন আগে', '%s এর দিন'], ['1 সপ্তাহ আগে', '1 সপ্তাহের মধ্যে'], ['%s এর সপ্তাহ আগে', '%s সপ্তাহের মধ্যে'], ['1 মাস আগে', '1 মাসে'], ['%s মাস আগে', '%s মাসে'], ['1 বছর আগে', '1 বছরের মধ্যে'], ['%s বছর আগে', '%s বছরে'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ca.ts000066400000000000000000000012501357731071200162240ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['fa un moment', "d'aquí un moment"], ['fa %s segons', "d'aquí %s segons"], ['fa 1 minut', "d'aquí 1 minut"], ['fa %s minuts', "d'aquí %s minuts"], ['fa 1 hora', "d'aquí 1 hora"], ['fa %s hores', "d'aquí %s hores"], ['fa 1 dia', "d'aquí 1 dia"], ['fa %s dies', "d'aquí %s dies"], ['fa 1 setmana', "d'aquí 1 setmana"], ['fa %s setmanes', "d'aquí %s setmanes"], ['fa 1 mes', "d'aquí 1 mes"], ['fa %s mesos', "d'aquí %s mesos"], ['fa 1 any', "d'aquí 1 any"], ['fa %s anys', "d'aquí %s anys"], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/cs.ts000066400000000000000000000022771357731071200162600ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { let inflectionIndex = 0; const isInflectionNeeded = index == 1 || index == 3 || index == 5 || index == 7 || index == 9 || index == 11 || index == 13; if (isInflectionNeeded && number >= 5) { inflectionIndex = 1; } return [ [['právě teď', 'právě teď']], [['před %s vteřinami', 'za %s vteřiny'], ['před %s vteřinami', 'za %s vteřin']], [['před minutou', 'za minutu']], [['před %s minutami', 'za %s minuty'], ['před %s minutami', 'za %s minut']], [['před hodinou', 'za hodinu']], [['před %s hodinami', 'za %s hodiny'], ['před %s hodinami', 'za %s hodin']], [['včera', 'zítra']], [['před %s dny', 'za %s dny'], ['před %s dny', 'za %s dnů']], [['minulý týden', 'příští týden']], [['před %s týdny', 'za %s týdny'], ['před %s týdny', 'za %s týdnů']], [['minulý měsíc', 'přístí měsíc']], [['před %s měsíci', 'za %s měsíce'], ['před %s měsíci', 'za %s měsíců']], [['před rokem', 'přístí rok']], [['před %s lety', 'za %s roky'], ['před %s lety', 'za %s let']], ][index][inflectionIndex] as [string, string]; } timeago.js-4.0.2/src/lang/da.ts000066400000000000000000000013121357731071200162240ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['for et øjeblik siden', 'om et øjeblik'], ['for %s sekunder siden', 'om %s sekunder'], ['for 1 minut siden', 'om 1 minut'], ['for %s minutter siden', 'om %s minutter'], ['for 1 time siden', 'om 1 time'], ['for %s timer siden', 'om %s timer'], ['for 1 dag siden', 'om 1 dag'], ['for %s dage siden', 'om %s dage'], ['for 1 uge siden', 'om 1 uge'], ['for %s uger siden', 'om %s uger'], ['for 1 måned siden', 'om 1 måned'], ['for %s måneder siden', 'om %s måneder'], ['for 1 år siden', 'om 1 år'], ['for %s år siden', 'om %s år'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/de.ts000066400000000000000000000012111357731071200162260ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['gerade eben', 'vor einer Weile'], ['vor %s Sekunden', 'in %s Sekunden'], ['vor 1 Minute', 'in 1 Minute'], ['vor %s Minuten', 'in %s Minuten'], ['vor 1 Stunde', 'in 1 Stunde'], ['vor %s Stunden', 'in %s Stunden'], ['vor 1 Tag', 'in 1 Tag'], ['vor %s Tagen', 'in %s Tagen'], ['vor 1 Woche', 'in 1 Woche'], ['vor %s Wochen', 'in %s Wochen'], ['vor 1 Monat', 'in 1 Monat'], ['vor %s Monaten', 'in %s Monaten'], ['vor 1 Jahr', 'in 1 Jahr'], ['vor %s Jahren', 'in %s Jahren'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/el.ts000066400000000000000000000016001357731071200162400ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['μόλις τώρα', 'σε λίγο'], ['%s δευτερόλεπτα πριν', 'σε %s δευτερόλεπτα'], ['1 λεπτό πριν', 'σε 1 λεπτό'], ['%s λεπτά πριν', 'σε %s λεπτά'], ['1 ώρα πριν', 'σε 1 ώρα'], ['%s ώρες πριν', 'σε %s ώρες'], ['1 μέρα πριν', 'σε 1 μέρα'], ['%s μέρες πριν', 'σε %s μέρες'], ['1 εβδομάδα πριν', 'σε 1 εβδομάδα'], ['%s εβδομάδες πριν', 'σε %s εβδομάδες'], ['1 μήνα πριν', 'σε 1 μήνα'], ['%s μήνες πριν', 'σε %s μήνες'], ['1 χρόνο πριν', 'σε 1 χρόνο'], ['%s χρόνια πριν', 'σε %s χρόνια'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/en_US.ts000066400000000000000000000005071357731071200166560ustar00rootroot00000000000000const EN_US = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year']; export default function(diff: number, idx: number): [string, string] { if (idx === 0) return ['just now', 'right now']; let unit = EN_US[Math.floor(idx / 2)]; if (diff > 1) unit += 's'; return [`${diff} ${unit} ago`, `in ${diff} ${unit}`]; } timeago.js-4.0.2/src/lang/en_short.ts000066400000000000000000000007621357731071200174710ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['just now', 'right now'], ['%ss ago', 'in %ss'], ['1m ago', 'in 1m'], ['%sm ago', 'in %sm'], ['1h ago', 'in 1h'], ['%sh ago', 'in %sh'], ['1d ago', 'in 1d'], ['%sd ago', 'in %sd'], ['1w ago', 'in 1w'], ['%sw ago', 'in %sw'], ['1mo ago', 'in 1mo'], ['%smo ago', 'in %smo'], ['1yr ago', 'in 1yr'], ['%syr ago', 'in %syr'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/es.ts000066400000000000000000000012051357731071200162500ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['justo ahora', 'en un rato'], ['hace %s segundos', 'en %s segundos'], ['hace 1 minuto', 'en 1 minuto'], ['hace %s minutos', 'en %s minutos'], ['hace 1 hora', 'en 1 hora'], ['hace %s horas', 'en %s horas'], ['hace 1 día', 'en 1 día'], ['hace %s días', 'en %s días'], ['hace 1 semana', 'en 1 semana'], ['hace %s semanas', 'en %s semanas'], ['hace 1 mes', 'en 1 mes'], ['hace %s meses', 'en %s meses'], ['hace 1 año', 'en 1 año'], ['hace %s años', 'en %s años'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/eu.ts000066400000000000000000000012721357731071200162560ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['orain', 'denbora bat barru'], ['duela %s segundu', '%s segundu barru'], ['duela minutu 1', 'minutu 1 barru'], ['duela %s minutu', '%s minutu barru'], ['duela ordu 1', 'ordu 1 barru'], ['duela %s ordu', '%s ordu barru'], ['duela egun 1', 'egun 1 barru'], ['duela %s egun', '%s egun barru'], ['duela aste 1', 'aste 1 barru'], ['duela %s aste', '%s aste barru'], ['duela hillabete 1', 'hillabete 1 barru'], ['duela %s hillabete', '%s hillabete barru'], ['duela urte 1', 'urte 1 barru'], ['duela %s urte', '%s urte barru'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/fa.ts000066400000000000000000000026401357731071200162330ustar00rootroot00000000000000// As persian language has different number symbols we need to replace regular numbers // to standard persian numbres. function toPersianNumber(number): string { // List of standard persian numbers from 0 to 9 const persianDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; return number.toString().replace(/\d/g, (x) => persianDigits[x]); } export default function(number: number, index: number): [string, string] { const formattedString = [ ['لحظاتی پیش', 'همین حالا'], ['%s ثانیه پیش', '%s ثانیه دیگر'], ['۱ دقیقه پیش', '۱ دقیقه دیگر'], ['%s دقیقه پیش', '%s دقیقه دیگر'], ['۱ ساعت پیش', '۱ ساعت دیگر'], ['%s ساعت پیش', '%s ساعت دیگر'], ['۱ روز پیش', '۱ روز دیگر'], ['%s روز پیش', '%s روز دیگر'], ['۱ هفته پیش', '۱ هفته دیگر'], ['%s هفته پیش', '%s هفته دیگر'], ['۱ ماه پیش', '۱ ماه دیگر'], ['%s ماه پیش', '%s ماه دیگر'], ['۱ سال پیش', '۱ سال دیگر'], ['%s سال پیش', '%s سال دیگر'], ][index]; // We convert regular numbers (%s) to standard persian numbers using toPersianNumber function return [ formattedString[0].replace('%s', toPersianNumber(number)), formattedString[1].replace('%s', toPersianNumber(number)), ]; } timeago.js-4.0.2/src/lang/fi.ts000066400000000000000000000014231357731071200162410ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['juuri äsken', 'juuri nyt'], ['%s sekuntia sitten', '%s sekunnin päästä'], ['minuutti sitten', 'minuutin päästä'], ['%s minuuttia sitten', '%s minuutin päästä'], ['tunti sitten', 'tunnin päästä'], ['%s tuntia sitten', '%s tunnin päästä'], ['päivä sitten', 'päivän päästä'], ['%s päivää sitten', '%s päivän päästä'], ['viikko sitten', 'viikon päästä'], ['%s viikkoa sitten', '%s viikon päästä'], ['kuukausi sitten', 'kuukauden päästä'], ['%s kuukautta sitten', '%s kuukauden päästä'], ['vuosi sitten', 'vuoden päästä'], ['%s vuotta sitten', '%s vuoden päästä'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/fr.ts000066400000000000000000000012771357731071200162610ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ["à l'instant", 'dans un instant'], ['il y a %s secondes', 'dans %s secondes'], ['il y a 1 minute', 'dans 1 minute'], ['il y a %s minutes', 'dans %s minutes'], ['il y a 1 heure', 'dans 1 heure'], ['il y a %s heures', 'dans %s heures'], ['il y a 1 jour', 'dans 1 jour'], ['il y a %s jours', 'dans %s jours'], ['il y a 1 semaine', 'dans 1 semaine'], ['il y a %s semaines', 'dans %s semaines'], ['il y a 1 mois', 'dans 1 mois'], ['il y a %s mois', 'dans %s mois'], ['il y a 1 an', 'dans 1 an'], ['il y a %s ans', 'dans %s ans'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/gl.ts000066400000000000000000000011711357731071200162450ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['xusto agora', 'daquí a un pouco'], ['hai %s segundos', 'en %s segundos'], ['hai 1 minuto', 'nun minuto'], ['hai %s minutos', 'en %s minutos'], ['hai 1 hora', 'nunha hora'], ['hai %s horas', 'en %s horas'], ['hai 1 día', 'nun día'], ['hai %s días', 'en %s días'], ['hai 1 semana', 'nunha semana'], ['hai %s semanas', 'en %s semanas'], ['hai 1 mes', 'nun mes'], ['hai %s meses', 'en %s meses'], ['hai 1 ano', 'nun ano'], ['hai %s anos', 'en %s anos'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/he.ts000066400000000000000000000022071357731071200162400ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['זה עתה', 'עכשיו'], ['לפני %s שניות', 'בעוד %s שניות'], ['לפני דקה', 'בעוד דקה'], ['לפני %s דקות', 'בעוד %s דקות'], ['לפני שעה', 'בעוד שעה'], number === 2 ? ['לפני שעתיים', 'בעוד שעתיים'] : ['לפני %s שעות', 'בעוד %s שעות'], ['אתמול', 'מחר'], number === 2 ? ['לפני יומיים', 'בעוד יומיים'] : ['לפני %s ימים', 'בעוד %s ימים'], ['לפני שבוע', 'בעוד שבוע'], number === 2 ? ['לפני שבועיים', 'בעוד שבועיים'] : ['לפני %s שבועות', 'בעוד %s שבועות'], ['לפני חודש', 'בעוד חודש'], number === 2 ? ['לפני חודשיים', 'בעוד חודשיים'] : ['לפני %s חודשים', 'בעוד %s חודשים'], ['לפני שנה', 'בעוד שנה'], number === 2 ? ['לפני שנתיים', 'בעוד שנתיים'] : ['לפני %s שנים', 'בעוד %s שנים'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/hi_IN.ts000066400000000000000000000020711357731071200166310ustar00rootroot00000000000000// Hindi (India) export default function(number: number, index: number): [string, string] { return [ ['अभी', 'कुछ समय'], ['%s सेकंड पहले', '%s सेकंड में'], ['1 मिनट पहले', '1 मिनट में'], ['%s मिनट पहले', '%s मिनट में'], ['1 घंटे पहले', '1 घंटे में'], ['%s घंटे पहले', '%s घंटे में'], ['1 दिन पहले', '1 दिन में'], ['%s दिन पहले', '%s दिनों में'], ['1 सप्ताह पहले', '1 सप्ताह में'], ['%s हफ्ते पहले', '%s हफ्तों में'], ['1 महीने पहले', '1 महीने में'], ['%s महीने पहले', '%s महीनों में'], ['1 साल पहले', '1 साल में'], ['%s साल पहले', '%s साल में'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/hu.ts000066400000000000000000000012201357731071200162520ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['éppen most', 'éppen most'], ['%s másodperce', '%s másodpercen belül'], ['1 perce', '1 percen belül'], ['%s perce', '%s percen belül'], ['1 órája', '1 órán belül'], ['%s órája', '%s órán belül'], ['1 napja', '1 napon belül'], ['%s napja', '%s napon belül'], ['1 hete', '1 héten belül'], ['%s hete', '%s héten belül'], ['1 hónapja', '1 hónapon belül'], ['%s hónapja', '%s hónapon belül'], ['1 éve', '1 éven belül'], ['%s éve', '%s éven belül'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/id_ID.ts000066400000000000000000000013631357731071200166160ustar00rootroot00000000000000// Indonesian (Indonesia) export default function(number: number, index: number): [string, string] { return [ ['baru saja', 'sebentar'], ['%s detik yang lalu', 'dalam %s detik'], ['1 menit yang lalu', 'dalam 1 menit'], ['%s menit yang lalu', 'dalam %s menit'], ['1 jam yang lalu', 'dalam 1 jam'], ['%s jam yang lalu', 'dalam %s jam'], ['1 hari yang lalu', 'dalam 1 hari'], ['%s hari yang lalu', 'dalam %s hari'], ['1 minggu yang lalu', 'dalam 1 minggu'], ['%s minggu yang lalu', 'dalam %s minggu'], ['1 bulan yang lalu', 'dalam 1 bulan'], ['%s bulan yang lalu', 'dalam %s bulan'], ['1 tahun yang lalu', 'dalam 1 tahun'], ['%s tahun yang lalu', 'dalam %s tahun'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/index.ts000066400000000000000000000031301357731071200167470ustar00rootroot00000000000000export { default as ar } from './ar'; export { default as be } from './be'; export { default as bg } from './bg'; export { default as bn_IN } from './bn_IN'; export { default as ca } from './ca'; export { default as de } from './de'; export { default as el } from './el'; export { default as en_short } from './en_short'; export { default as en_US } from './en_US'; export { default as es } from './es'; export { default as eu } from './eu'; export { default as fa } from './fa'; export { default as fi } from './fi'; export { default as fr } from './fr'; export { default as gl } from './gl'; export { default as he } from './he'; export { default as hi_IN } from './hi_IN'; export { default as hu } from './hu'; export { default as id_ID } from './id_ID'; export { default as it } from './it'; export { default as ja } from './ja'; export { default as ko } from './ko'; export { default as ml } from './ml'; export { default as my } from './my'; export { default as nb_NO } from './nb_NO'; export { default as nl } from './nl'; export { default as nn_NO } from './nn_NO'; export { default as pl } from './pl'; export { default as pt_BR } from './pt_BR'; export { default as ro } from './ro'; export { default as ru } from './ru'; export { default as sq } from './sq'; export { default as sr } from './sr'; export { default as sv } from './sv'; export { default as ta } from './ta'; export { default as th } from './th'; export { default as tr } from './tr'; export { default as uk } from './uk'; export { default as vi } from './vi'; export { default as zh_CN } from './zh_CN'; export { default as zh_TW } from './zh_TW'; timeago.js-4.0.2/src/lang/it.ts000066400000000000000000000012041357731071200162540ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['poco fa', 'fra poco'], ['%s secondi fa', 'fra %s secondi'], ['un minuto fa', 'fra un minuto'], ['%s minuti fa', 'fra %s minuti'], ["un'ora fa", "fra un'ora"], ['%s ore fa', 'fra %s ore'], ['un giorno fa', 'fra un giorno'], ['%s giorni fa', 'fra %s giorni'], ['una settimana fa', 'fra una settimana'], ['%s settimane fa', 'fra %s settimane'], ['un mese fa', 'fra un mese'], ['%s mesi fa', 'fra %s mesi'], ['un anno fa', 'fra un anno'], ['%s anni fa', 'fra %s anni'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ja.ts000066400000000000000000000011401357731071200162310ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['すこし前', 'すぐに'], ['%s秒前', '%s秒以内'], ['1分前', '1分以内'], ['%s分前', '%s分以内'], ['1時間前', '1時間以内'], ['%s時間前', '%s時間以内'], ['1日前', '1日以内'], ['%s日前', '%s日以内'], ['1週間前', '1週間以内'], ['%s週間前', '%s週間以内'], ['1ヶ月前', '1ヶ月以内'], ['%sヶ月前', '%sヶ月以内'], ['1年前', '1年以内'], ['%s年前', '%s年以内'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ka.ts000066400000000000000000000017111357731071200162360ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['ამ წამს', 'ახლა'], ['%s წამის წინ', '%s წამში'], ['1 წუთის წინ', '1 წუთში'], ['%s წუთის წინ', '%s წუთში'], ['1 საათის წინ', '1 საათში'], ['%s საათის წინ', '%s საათში'], ['1 დღის წინ', '1 დღეში'], ['%s დღის წინ', '%s დღეში'], ['1 კვირის წინ', '1 კვირაში'], ['%s კვირის წინ', '%s კვირაში'], ['1 თვის წინ', '1 თვეში'], ['%s თვის წინ', '%s თვეში'], ['1 წლის წინ', '1 წელიწადში'], ['%s წლის წინ', '%s წელიწადში'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ko.ts000066400000000000000000000011071357731071200162530ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['방금', '곧'], ['%s초 전', '%s초 후'], ['1분 전', '1분 후'], ['%s분 전', '%s분 후'], ['1시간 전', '1시간 후'], ['%s시간 전', '%s시간 후'], ['1일 전', '1일 후'], ['%s일 전', '%s일 후'], ['1주일 전', '1주일 후'], ['%s주일 전', '%s주일 후'], ['1개월 전', '1개월 후'], ['%s개월 전', '%s개월 후'], ['1년 전', '1년 후'], ['%s년 전', '%s년 후'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ml.ts000066400000000000000000000033761357731071200162640ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['ഇപ്പോള്‍', 'കുറച്ചു മുന്‍പ്'], ['%s സെക്കന്റ്‌കള്‍ക്ക് മുന്‍പ്', '%s സെക്കന്റില്‍'], ['1 മിനിറ്റിനു മുന്‍പ്', '1 മിനിറ്റില്‍'], ['%s മിനിറ്റുകള്‍ക്ക് മുന്‍പ', '%s മിനിറ്റില്‍'], ['1 മണിക്കൂറിനു മുന്‍പ്', '1 മണിക്കൂറില്‍'], ['%s മണിക്കൂറുകള്‍ക്കു മുന്‍പ്', '%s മണിക്കൂറില്‍'], ['1 ഒരു ദിവസം മുന്‍പ്', '1 ദിവസത്തില്‍'], ['%s ദിവസങ്ങള്‍ക് മുന്‍പ്', '%s ദിവസങ്ങള്‍ക്കുള്ളില്‍'], ['1 ആഴ്ച മുന്‍പ്', '1 ആഴ്ചയില്‍'], ['%s ആഴ്ചകള്‍ക്ക് മുന്‍പ്', '%s ആഴ്ചകള്‍ക്കുള്ളില്‍'], ['1 മാസത്തിനു മുന്‍പ്', '1 മാസത്തിനുള്ളില്‍'], ['%s മാസങ്ങള്‍ക്ക് മുന്‍പ്', '%s മാസങ്ങള്‍ക്കുള്ളില്‍'], ['1 വര്‍ഷത്തിനു മുന്‍പ്', '1 വര്‍ഷത്തിനുള്ളില്‍'], ['%s വര്‍ഷങ്ങള്‍ക്കു മുന്‍പ്', '%s വര്‍ഷങ്ങള്‍ക്കുല്ല്ളില്‍'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/my.ts000066400000000000000000000021661357731071200162750ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['ယခုအတွင်း', 'ယခု'], ['%s စက္ကန့် အကြာက', '%s စက္ကန့်အတွင်း'], ['1 မိနစ် အကြာက', '1 မိနစ်အတွင်း'], ['%s မိနစ် အကြာက', '%s မိနစ်အတွင်း'], ['1 နာရီ အကြာက', '1 နာရီအတွင်း'], ['%s နာရီ အကြာက', '%s နာရီအတွင်း'], ['1 ရက် အကြာက', '1 ရက်အတွင်း'], ['%s ရက် အကြာက', '%s ရက်အတွင်း'], ['1 ပတ် အကြာက', '1 ပတ်အတွင်း'], ['%s ပတ် အကြာက', '%s ပတ်အတွင်း'], ['1 လ အကြာက', '1 လအတွင်း'], ['%s လ အကြာက', '%s လအတွင်း'], ['1 နှစ် အကြာက', '1 နှစ်အတွင်း'], ['%s နှစ် အကြာက', '%s နှစ်အတွင်း'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/nb_NO.ts000066400000000000000000000012331357731071200166350ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['akkurat nå', 'om litt'], ['%s sekunder siden', 'om %s sekunder'], ['1 minutt siden', 'om 1 minutt'], ['%s minutter siden', 'om %s minutter'], ['1 time siden', 'om 1 time'], ['%s timer siden', 'om %s timer'], ['1 dag siden', 'om 1 dag'], ['%s dager siden', 'om %s dager'], ['1 uke siden', 'om 1 uke'], ['%s uker siden', 'om %s uker'], ['1 måned siden', 'om 1 måned'], ['%s måneder siden', 'om %s måneder'], ['1 år siden', 'om 1 år'], ['%s år siden', 'om %s år'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/nl.ts000066400000000000000000000013211357731071200162510ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['recent', 'binnenkort'], ['%s seconden geleden', 'binnen %s seconden'], ['1 minuut geleden', 'binnen 1 minuut'], ['%s minuten geleden', 'binnen %s minuten'], ['1 uur geleden', 'binnen 1 uur'], ['%s uur geleden', 'binnen %s uur'], ['1 dag geleden', 'binnen 1 dag'], ['%s dagen geleden', 'binnen %s dagen'], ['1 week geleden', 'binnen 1 week'], ['%s weken geleden', 'binnen %s weken'], ['1 maand geleden', 'binnen 1 maand'], ['%s maanden geleden', 'binnen %s maanden'], ['1 jaar geleden', 'binnen 1 jaar'], ['%s jaar geleden', 'binnen %s jaar'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/nn_NO.ts000066400000000000000000000012231357731071200166500ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['nett no', 'om litt'], ['%s sekund sidan', 'om %s sekund'], ['1 minutt sidan', 'om 1 minutt'], ['%s minutt sidan', 'om %s minutt'], ['1 time sidan', 'om 1 time'], ['%s timar sidan', 'om %s timar'], ['1 dag sidan', 'om 1 dag'], ['%s dagar sidan', 'om %s dagar'], ['1 veke sidan', 'om 1 veke'], ['%s veker sidan', 'om %s veker'], ['1 månad sidan', 'om 1 månad'], ['%s månadar sidan', 'om %s månadar'], ['1 år sidan', 'om 1 år'], ['%s år sidan', 'om %s år'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/oc.ts000066400000000000000000000012541357731071200162460ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['fa un moment', "d'aquí un moment"], ['fa %s segondas', "d'aquí %s segondas"], ['fa 1 minuta', "d'aquí 1 minuta"], ['fa %s minutas', "d'aquí %s minutas"], ['fa 1 ora', "d'aquí 1 ora"], ['fa %s oras', "d'aquí %s oras"], ['fa 1 jorn', "d'aquí 1 jorn"], ['fa %s jorns', "d'aquí %s jorns"], ['fa 1 setmana', "d'aquí 1 setmana"], ['fa %s setmanas', "d'aquí %s setmanas"], ['fa 1 mes', "d'aquí 1 mes"], ['fa %s meses', "d'aquí %s meses"], ['fa 1 an', "d'aquí 1 an"], ['fa %s ans', "d'aquí %s ans"], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/pl.ts000066400000000000000000000027161357731071200162640ustar00rootroot00000000000000// 0-13 alternately: single unit of time, // genitive plural form for all other numbers excluding cases below: // 14-20: nominative plural form for the numbers 2,3,4 // and all other numbers higher than 21 which end in 2,3,4 const l = [ ['w tej chwili', 'za chwilę'], ['%s sekund temu', 'za %s sekund'], ['1 minutę temu', 'za 1 minutę'], ['%s minut temu', 'za %s minut'], ['1 godzinę temu', 'za 1 godzinę'], ['%s godzin temu', 'za %s godzin'], ['1 dzień temu', 'za 1 dzień'], // ['wczoraj', 'jutro'], ['%s dni temu', 'za %s dni'], ['1 tydzień temu', 'za 1 tydzień'], ['%s tygodni temu', 'za %s tygodni'], ['1 miesiąc temu', 'za 1 miesiąc'], ['%s miesięcy temu', 'za %s miesięcy'], ['1 rok temu', 'za 1 rok'], ['%s lat temu', 'za %s lat'], ['%s sekundy temu', 'za %s sekundy'], ['%s minuty temu', 'za %s minuty'], ['%s godziny temu', 'za %s godziny'], ['%s dni temu', 'za %s dni'], ['%s tygodnie temu', 'za %s tygodnie'], ['%s miesiące temu', 'za %s miesiące'], ['%s lata temu', 'za %s lata'], ]; export default function(number: number, index: number): [string, string] { // to determine which plural form must be used check the last 2 digits // and calculate new index value to get the nominative form (14-20) // for all other cases use index value as it is (0-13) return l[ index & 1 ? (number % 10 > 4 || number % 10 < 2 || 1 === ~~(number / 10) % 10 ? index : ++index / 2 + 13) : index ] as [string, string]; } timeago.js-4.0.2/src/lang/pt_BR.ts000066400000000000000000000011751357731071200166550ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['agora mesmo', 'agora'], ['há %s segundos', 'em %s segundos'], ['há um minuto', 'em um minuto'], ['há %s minutos', 'em %s minutos'], ['há uma hora', 'em uma hora'], ['há %s horas', 'em %s horas'], ['há um dia', 'em um dia'], ['há %s dias', 'em %s dias'], ['há uma semana', 'em uma semana'], ['há %s semanas', 'em %s semanas'], ['há um mês', 'em um mês'], ['há %s meses', 'em %s meses'], ['há um ano', 'em um ano'], ['há %s anos', 'em %s anos'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ro.ts000066400000000000000000000016771357731071200162760ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { const langTable = [ ['chiar acum', 'chiar acum'], ['acum %s secunde', 'peste %s secunde'], ['acum un minut', 'peste un minut'], ['acum %s minute', 'peste %s minute'], ['acum o oră', 'peste o oră'], ['acum %s ore', 'peste %s ore'], ['acum o zi', 'peste o zi'], ['acum %s zile', 'peste %s zile'], ['acum o săptămână', 'peste o săptămână'], ['acum %s săptămâni', 'peste %s săptămâni'], ['acum o lună', 'peste o lună'], ['acum %s luni', 'peste %s luni'], ['acum un an', 'peste un an'], ['acum %s ani', 'peste %s ani'], ]; if (number < 20) { return langTable[index] as [string, string]; } // A `de` preposition must be added between the number and the adverb // if the number is greater than 20. return [langTable[index][0].replace('%s', '%s de'), langTable[index][1].replace('%s', '%s de')]; } timeago.js-4.0.2/src/lang/ru.ts000066400000000000000000000045131357731071200162740ustar00rootroot00000000000000/** * * @param f1 - 1 * @param f - 21, 31, ... * @param s - 2-4, 22-24, 32-34 ... * @param t - 5-20, 25-30, ... * @param n * @returns */ function formatNum(f1: string, f: string, s: string, t: string, n: number): string { const n10 = n % 10; let str = t; if (n === 1) { str = f1; } else if (n10 === 1 && n > 20) { str = f; } else if (n10 > 1 && n10 < 5 && (n > 20 || n < 10)) { str = s; } return str; } const seconds = formatNum.bind(null, 'секунду', '%s секунду', '%s секунды', '%s секунд'), minutes = formatNum.bind(null, 'минуту', '%s минуту', '%s минуты', '%s минут'), hours = formatNum.bind(null, 'час', '%s час', '%s часа', '%s часов'), days = formatNum.bind(null, 'день', '%s день', '%s дня', '%s дней'), weeks = formatNum.bind(null, 'неделю', '%s неделю', '%s недели', '%s недель'), months = formatNum.bind(null, 'месяц', '%s месяц', '%s месяца', '%s месяцев'), years = formatNum.bind(null, 'год', '%s год', '%s года', '%s лет'); export default function(number: number, index: number): [string, string] { switch (index) { case 0: return ['только что', 'через несколько секунд']; case 1: return [seconds(number) + ' назад', 'через ' + seconds(number)]; case 2: // ['минуту назад', 'через минуту']; case 3: return [minutes(number) + ' назад', 'через ' + minutes(number)]; case 4: // ['час назад', 'через час']; case 5: return [hours(number) + ' назад', 'через ' + hours(number)]; case 6: return ['вчера', 'завтра']; case 7: return [days(number) + ' назад', 'через ' + days(number)]; case 8: // ['неделю назад', 'через неделю']; case 9: return [weeks(number) + ' назад', 'через ' + weeks(number)]; case 10: // ['месяц назад', 'через месяц']; case 11: return [months(number) + ' назад', 'через ' + months(number)]; case 12: // ['год назад', 'через год']; case 13: return [years(number) + ' назад', 'через ' + years(number)]; default: return ['', '']; } } timeago.js-4.0.2/src/lang/sq.ts000066400000000000000000000012631357731071200162700ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['pak më parë', 'pas pak'], ['para %s sekondash', 'pas %s sekondash'], ['para një minute', 'pas një minute'], ['para %s minutash', 'pas %s minutash'], ['para një ore', 'pas një ore'], ['para %s orësh', 'pas %s orësh'], ['dje', 'nesër'], ['para %s ditësh', 'pas %s ditësh'], ['para një jave', 'pas një jave'], ['para %s javësh', 'pas %s javësh'], ['para një muaji', 'pas një muaji'], ['para %s muajsh', 'pas %s muajsh'], ['para një viti', 'pas një viti'], ['para %s vjetësh', 'pas %s vjetësh'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/sr.ts000066400000000000000000000036471357731071200163010ustar00rootroot00000000000000function formatNum(single: string, one: string, few: string, other: string, n: number): string { const rem10 = n % 10; const rem100 = n % 100; if (n == 1) { return single; } else if (rem10 == 1 && rem100 != 11) { return one; } else if (rem10 >= 2 && rem10 <= 4 && !(rem100 >= 12 && rem100 <= 14)) { return few; } else { return other; } } const seconds = formatNum.bind(null, '1 секунд', '%s секунд', '%s секунде', '%s секунди'), minutes = formatNum.bind(null, '1 минут', '%s минут', '%s минуте', '%s минута'), hours = formatNum.bind(null, 'сат времена', '%s сат', '%s сата', '%s сати'), days = formatNum.bind(null, '1 дан', '%s дан', '%s дана', '%s дана'), weeks = formatNum.bind(null, 'недељу дана', '%s недељу', '%s недеље', '%s недеља'), months = formatNum.bind(null, 'месец дана', '%s месец', '%s месеца', '%s месеци'), years = formatNum.bind(null, 'годину дана', '%s годину', '%s године', '%s година'); export default function(number: number, index: number): [string, string] { switch (index) { case 0: return ['малопре', 'управо сад']; case 1: return ['пре ' + seconds(number), 'за ' + seconds(number)]; case 2: case 3: return ['пре ' + minutes(number), 'за ' + minutes(number)]; case 4: case 5: return ['пре ' + hours(number), 'за ' + hours(number)]; case 6: case 7: return ['пре ' + days(number), 'за ' + days(number)]; case 8: case 9: return ['пре ' + weeks(number), 'за ' + weeks(number)]; case 10: case 11: return ['пре ' + months(number), 'за ' + months(number)]; case 12: case 13: return ['пре ' + years(number), 'за ' + years(number)]; default: return ['', '']; } } timeago.js-4.0.2/src/lang/sv.ts000066400000000000000000000012211357731071200162670ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['just nu', 'om en stund'], ['%s sekunder sedan', 'om %s sekunder'], ['1 minut sedan', 'om 1 minut'], ['%s minuter sedan', 'om %s minuter'], ['1 timme sedan', 'om 1 timme'], ['%s timmar sedan', 'om %s timmar'], ['1 dag sedan', 'om 1 dag'], ['%s dagar sedan', 'om %s dagar'], ['1 vecka sedan', 'om 1 vecka'], ['%s veckor sedan', 'om %s veckor'], ['1 månad sedan', 'om 1 månad'], ['%s månader sedan', 'om %s månader'], ['1 år sedan', 'om 1 år'], ['%s år sedan', 'om %s år'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/ta.ts000066400000000000000000000027471357731071200162610ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['இப்போது', 'சற்று நேரம் முன்பு'], ['%s நொடிக்கு முன்', '%s நொடிகளில்'], ['1 நிமிடத்திற்க்கு முன்', '1 நிமிடத்தில்'], ['%s நிமிடத்திற்க்கு முன்', '%s நிமிடங்களில்'], ['1 மணி நேரத்திற்கு முன்', '1 மணி நேரத்திற்குள்'], ['%s மணி நேரத்திற்கு முன்', '%s மணி நேரத்திற்குள்'], ['1 நாளுக்கு முன்', '1 நாளில்'], ['%s நாட்களுக்கு முன்', '%s நாட்களில்'], ['1 வாரத்திற்கு முன்', '1 வாரத்தில்'], ['%s வாரங்களுக்கு முன்', '%s வாரங்களில்'], ['1 மாதத்திற்கு முன்', '1 மாதத்தில்'], ['%s மாதங்களுக்கு முன்', '%s மாதங்களில்'], ['1 வருடத்திற்கு முன்', '1 வருடத்தில்'], ['%s வருடங்களுக்கு முன்', '%s வருடங்களில்'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/th.ts000066400000000000000000000022511357731071200162560ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['เมื่อสักครู่นี้', 'อีกสักครู่'], ['%s วินาทีที่แล้ว', 'ใน %s วินาที'], ['1 นาทีที่แล้ว', 'ใน 1 นาที'], ['%s นาทีที่แล้ว', 'ใน %s นาที'], ['1 ชั่วโมงที่แล้ว', 'ใน 1 ชั่วโมง'], ['%s ชั่วโมงที่แล้ว', 'ใน %s ชั่วโมง'], ['1 วันที่แล้ว', 'ใน 1 วัน'], ['%s วันที่แล้ว', 'ใน %s วัน'], ['1 อาทิตย์ที่แล้ว', 'ใน 1 อาทิตย์'], ['%s อาทิตย์ที่แล้ว', 'ใน %s อาทิตย์'], ['1 เดือนที่แล้ว', 'ใน 1 เดือน'], ['%s เดือนที่แล้ว', 'ใน %s เดือน'], ['1 ปีที่แล้ว', 'ใน 1 ปี'], ['%s ปีที่แล้ว', 'ใน %s ปี'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/tr.ts000066400000000000000000000012621357731071200162710ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['az önce', 'şimdi'], ['%s saniye önce', '%s saniye içinde'], ['1 dakika önce', '1 dakika içinde'], ['%s dakika önce', '%s dakika içinde'], ['1 saat önce', '1 saat içinde'], ['%s saat önce', '%s saat içinde'], ['1 gün önce', '1 gün içinde'], ['%s gün önce', '%s gün içinde'], ['1 hafta önce', '1 hafta içinde'], ['%s hafta önce', '%s hafta içinde'], ['1 ay önce', '1 ay içinde'], ['%s ay önce', '%s ay içinde'], ['1 yıl önce', '1 yıl içinde'], ['%s yıl önce', '%s yıl içinde'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/uk.ts000066400000000000000000000036161357731071200162700ustar00rootroot00000000000000function formatNum(f1: string, f: string, s: string, t: string, n: number): string { const n10 = n % 10; let str = t; if (n === 1) { str = f1; } else if (n10 === 1 && n > 20) { str = f; } else if (n10 > 1 && n10 < 5 && (n > 20 || n < 10)) { str = s; } return str; } const seconds = formatNum.bind(null, 'секунду', '%s секунду', '%s секунди', '%s секунд'), minutes = formatNum.bind(null, 'хвилину', '%s хвилину', '%s хвилини', '%s хвилин'), hours = formatNum.bind(null, 'годину', '%s годину', '%s години', '%s годин'), days = formatNum.bind(null, 'день', '%s день', '%s дні', '%s днів'), weeks = formatNum.bind(null, 'тиждень', '%s тиждень', '%s тиждні', '%s тижднів'), months = formatNum.bind(null, 'місяць', '%s місяць', '%s місяці', '%s місяців'), years = formatNum.bind(null, 'рік', '%s рік', '%s роки', '%s років'); export default function(number: number, index: number): [string, string] { switch (index) { case 0: return ['щойно', 'через декілька секунд']; case 1: return [seconds(number) + ' тому', 'через ' + seconds(number)]; case 2: case 3: return [minutes(number) + ' тому', 'через ' + minutes(number)]; case 4: case 5: return [hours(number) + ' тому', 'через ' + hours(number)]; case 6: case 7: return [days(number) + ' тому', 'через ' + days(number)]; case 8: case 9: return [weeks(number) + ' тому', 'через ' + weeks(number)]; case 10: case 11: return [months(number) + ' тому', 'через ' + months(number)]; case 12: case 13: return [years(number) + ' тому', 'через ' + years(number)]; default: return ['', '']; } } timeago.js-4.0.2/src/lang/vi.ts000066400000000000000000000013331357731071200162610ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['vừa xong', 'một lúc'], ['%s giây trước', 'trong %s giây'], ['1 phút trước', 'trong 1 phút'], ['%s phút trước', 'trong %s phút'], ['1 giờ trước', 'trong 1 giờ'], ['%s giờ trước', 'trong %s giờ'], ['1 ngày trước', 'trong 1 ngày'], ['%s ngày trước', 'trong %s ngày'], ['1 tuần trước', 'trong 1 tuần'], ['%s tuần trước', 'trong %s tuần'], ['1 tháng trước', 'trong 1 tháng'], ['%s tháng trước', 'trong %s tháng'], ['1 năm trước', 'trong 1 năm'], ['%s năm trước', 'trong %s năm'], ][index] as [string, string]; } timeago.js-4.0.2/src/lang/zh_CN.ts000066400000000000000000000004371357731071200166500ustar00rootroot00000000000000const ZH_CN = ['秒', '分钟', '小时', '天', '周', '个月', '年']; export default function(diff: number, idx: number): [string, string] { if (idx === 0) return ['刚刚', '片刻后']; const unit = ZH_CN[~~(idx / 2)]; return [`${diff} ${unit}前`, `${diff} ${unit}后`]; } timeago.js-4.0.2/src/lang/zh_TW.ts000066400000000000000000000011151357731071200166740ustar00rootroot00000000000000export default function(number: number, index: number): [string, string] { return [ ['剛剛', '片刻後'], ['%s 秒前', '%s 秒後'], ['1 分鐘前', '1 分鐘後'], ['%s 分鐘前', '%s 分鐘後'], ['1 小時前', '1 小時後'], ['%s 小時前', '%s 小時後'], ['1 天前', '1 天後'], ['%s 天前', '%s 天後'], ['1 週前', '1 週後'], ['%s 週前', '%s 週後'], ['1 個月前', '1 個月後'], ['%s 個月前', '%s 個月後'], ['1 年前', '1 年後'], ['%s 年前', '%s 年後'], ][index] as [string, string]; } timeago.js-4.0.2/src/realtime.ts000066400000000000000000000033651357731071200165330ustar00rootroot00000000000000import { setTimerId, getTimerId, getDateAttribute } from './utils/dom'; import { formatDiff, diffSec, nextInterval } from './utils/date'; import { getLocale } from './register'; import { LocaleFunc, Opts, TimerPool } from './interface'; // all realtime timer const TIMER_POOL: TimerPool = {}; /** * clear a timer from pool * @param tid */ const clear = (tid: number): void => { clearTimeout(tid); delete TIMER_POOL[tid]; }; // run with timer(setTimeout) function run(node: HTMLElement, date: string, localeFunc: LocaleFunc, opts: Opts): void { // clear the node's exist timer clear(getTimerId(node)); const { relativeDate, minInterval } = opts; // get diff seconds const diff = diffSec(date, relativeDate); // render node.innerText = formatDiff(diff, localeFunc); const tid = (setTimeout(() => { run(node, date, localeFunc, opts); }, Math.min(Math.max(nextInterval(diff), minInterval || 1) * 1000, 0x7fffffff)) as unknown) as number; // there is no need to save node in object. Just save the key TIMER_POOL[tid] = 0; setTimerId(node, tid); } /** * cancel a timer or all timers * @param node - node hosting the time string */ export function cancel(node?: HTMLElement): void { // cancel one if (node) clear(getTimerId(node)); // cancel all // @ts-ignore else Object.keys(TIMER_POOL).forEach(clear); } /** * render a dom realtime * @param nodes * @param locale * @param opts */ export function render(nodes: HTMLElement | HTMLElement[] | NodeList, locale?: string, opts?: Opts) { // by .length // @ts-ignore const nodeList: HTMLElement[] = nodes.length ? nodes : [nodes]; nodeList.forEach((node: HTMLElement) => { run(node, getDateAttribute(node), getLocale(locale), opts || {}); }); return nodeList; } timeago.js-4.0.2/src/register.ts000066400000000000000000000010121357731071200165400ustar00rootroot00000000000000/** * Created by hustcc on 18/5/20. * Contract: i@hust.cc */ import { LocaleFunc, LocaleMap } from './interface'; /** * All supported locales */ const Locales: LocaleMap = {}; /** * register a locale * @param locale * @param func */ export const register = (locale: string, func: LocaleFunc) => { Locales[locale] = func; }; /** * get a locale, default is en_US * @param locale * @returns {*} */ export const getLocale = (locale: string): LocaleFunc => { return Locales[locale] || Locales['en_US']; }; timeago.js-4.0.2/src/utils/000077500000000000000000000000001357731071200155125ustar00rootroot00000000000000timeago.js-4.0.2/src/utils/date.ts000066400000000000000000000061771357731071200170120ustar00rootroot00000000000000/** * Created by hustcc on 18/5/20. * Contract: i@hust.cc */ import { LocaleFunc, TDate } from '../interface'; const SEC_ARRAY = [ 60, // 60 seconds in 1 min 60, // 60 mins in 1 hour 24, // 24 hours in 1 day 7, // 7 days in 1 week 365 / 7 / 12, // 4.345238095238096 weeks in 1 month 12, // 12 months in 1 year ]; /** * format Date / string / timestamp to timestamp * @param input * @returns {*} */ export function toDate(input?: Date | string | number): Date { if (input instanceof Date) return input; // @ts-ignore if (!isNaN(input) || /^\d+$/.test(input)) return new Date(parseInt(input)); input = (input || '') // @ts-ignore .trim() .replace(/\.\d+/, '') // remove milliseconds .replace(/-/, '/') .replace(/-/, '/') .replace(/(\d)T(\d)/, '$1 $2') .replace(/Z/, ' UTC') // 2017-2-5T3:57:52Z -> 2017-2-5 3:57:52UTC .replace(/([+-]\d\d):?(\d\d)/, ' $1$2'); // -04:00 -> -0400 return new Date(input); } /** * format the diff second to *** time ago, with setting locale * @param diff * @param localeFunc * @returns */ export function formatDiff(diff: number, localeFunc: LocaleFunc): string { /** * if locale is not exist, use defaultLocale. * if defaultLocale is not exist, use build-in `en`. * be sure of no error when locale is not exist. * * If `time in`, then 1 * If `time ago`, then 0 */ const agoIn = diff < 0 ? 1 : 0; /** * Get absolute value of number (|diff| is non-negative) value of x * |diff| = diff if diff is positive * |diff| = -diff if diff is negative * |0| = 0 */ diff = Math.abs(diff); /** * Time in seconds */ const totalSec = diff; /** * Unit of time */ let idx = 0; for (; diff >= SEC_ARRAY[idx] && idx < SEC_ARRAY.length; idx++) { diff /= SEC_ARRAY[idx]; } /** * Math.floor() is alternative of ~~ * * The differences and bugs: * Math.floor(3.7) -> 4 but ~~3.7 -> 3 * Math.floor(1559125440000.6) -> 1559125440000 but ~~1559125440000.6 -> 52311552 * * More information about the performance of algebraic: * https://www.youtube.com/watch?v=65-RbBwZQdU */ diff = Math.floor(diff); idx *= 2; if (diff > (idx === 0 ? 9 : 1)) idx += 1; return localeFunc(diff, idx, totalSec)[agoIn].replace('%s', diff.toString()); } /** * calculate the diff second between date to be formatted an now date. * @param date * @param relativeDate * @returns {number} */ export function diffSec(date: TDate, relativeDate: TDate): number { const relDate = relativeDate ? toDate(relativeDate) : new Date(); return (+relDate - +toDate(date)) / 1000; } /** * nextInterval: calculate the next interval time. * - diff: the diff sec between now and date to be formatted. * * What's the meaning? * diff = 61 then return 59 * diff = 3601 (an hour + 1 second), then return 3599 * make the interval with high performance. **/ export function nextInterval(diff: number): number { let rst = 1, i = 0, d = Math.abs(diff); for (; diff >= SEC_ARRAY[i] && i < SEC_ARRAY.length; i++) { diff /= SEC_ARRAY[i]; rst *= SEC_ARRAY[i]; } d = d % rst; d = d ? rst - d : rst; return Math.ceil(d); } timeago.js-4.0.2/src/utils/dom.ts000066400000000000000000000011671357731071200166460ustar00rootroot00000000000000const ATTR_TIMEAGO_TID = 'timeago-id'; /** * get the datetime attribute, `datetime` are supported. * @param node * @returns {*} */ export function getDateAttribute(node: HTMLElement): string { return node.getAttribute('datetime'); } /** * set the node attribute, native DOM * @param node * @param timerId * @returns {*} */ export function setTimerId(node: HTMLElement, timerId: number): void { // @ts-ignore node.setAttribute(ATTR_TIMEAGO_TID, timerId); } /** * get the timer id * @param node */ export function getTimerId(node: HTMLElement): number { return parseInt(node.getAttribute(ATTR_TIMEAGO_TID)); } timeago.js-4.0.2/tsconfig.ci.json000066400000000000000000000001201357731071200166550ustar00rootroot00000000000000{ "extends": "./tsconfig.json", "include": ["src/**/*", "__tests__/**/*"] } timeago.js-4.0.2/tsconfig.json000066400000000000000000000006131357731071200162720ustar00rootroot00000000000000{ "compilerOptions": { "target": "es5", "jsx": "preserve", "moduleResolution": "node", "experimentalDecorators": true, "declaration": true, "sourceMap": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, "pretty": true, "lib": ["dom", "esnext"], "skipLibCheck": true }, "include": ["src/**/*"], "exclude": ["node_modules"] }