Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .commitlintrc.js

This file was deleted.

18 changes: 0 additions & 18 deletions .eslintrc

This file was deleted.

20 changes: 7 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ on: [push]

jobs:
build:
runs-on: macOS-latest
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x,9.x,10.x,11.x,12.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
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 }}
- run: npm install
- run: npm run build
- run: npm test
18 changes: 18 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: deploy

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy site to gh-pages branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
cname: timeago.ling.pub
14 changes: 0 additions & 14 deletions .github/workflows/rebase.yml

This file was deleted.

56 changes: 0 additions & 56 deletions .github/workflows/release.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- 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).
[Official website](https://timeago.ling.pub/). 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/)
Expand Down
15 changes: 10 additions & 5 deletions __tests__/format.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/

import { vi } from 'vitest';
import { format } from '../src/';

describe('format', () => {
Expand All @@ -16,4 +12,13 @@ describe('format', () => {

expect(format(+now - 1000 * 1000, 'not-exist-locale', { relativeDate: now })).toBe('16 minutes ago');
});

test('format with fake time', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2024-01-01T00:00:00Z'));
const date = new Date('2024-01-01T00:00:00Z');
expect(format(date)).toBe('just now');
vi.useRealTimers();
});
});

8 changes: 2 additions & 6 deletions __tests__/full.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* 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';
Expand All @@ -17,7 +12,8 @@ describe('timeago.js full', () => {

test('locales', () => {
Object.keys(Locales).forEach((key: string) => {
expect(getLocale(key)).toBe(Locales[key]);
expect(getLocale(key)).toBe(Locales[key as keyof typeof Locales]);
});
});
});

6 changes: 1 addition & 5 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* Created by hustcc on 18/5/20.
* Contract: i@hust.cc
*/

import { format, render, cancel, register } from '../src/';
import { getLocale } from '../src/register';

Expand Down Expand Up @@ -71,3 +66,4 @@ describe('timeago.js core', () => {
});
});
});

63 changes: 32 additions & 31 deletions __tests__/lang/an.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { advanceTo, clear } from 'jest-date-mock';

import { register, format } from '../../src';
import an from '../../src/lang/an';

Expand All @@ -7,97 +7,98 @@ register('an', an);
let date = new Date();

beforeEach(() => {
advanceTo(0);
vi.useFakeTimers();
vi.setSystemTime(0);
date = new Date();
});
afterEach(() => {
clear();
vi.useRealTimers();
});
describe('an', () => {
test('time ago', () => {
advanceTo(9 * 1000);
vi.setSystemTime(9 * 1000);
expect(format(date, 'an')).toEqual('fa un momento');

advanceTo(30 * 1000);
vi.setSystemTime(30 * 1000);
expect(format(date, 'an')).toEqual('fa 30 segundos');

advanceTo(1000 * 60);
vi.setSystemTime(1000 * 60);
expect(format(date, 'an')).toEqual('fa 1 minuto');

advanceTo(1000 * 60 * 30);
vi.setSystemTime(1000 * 60 * 30);
expect(format(date, 'an')).toEqual('fa 30 minutos');

advanceTo(1000 * 60 * 60);
vi.setSystemTime(1000 * 60 * 60);
expect(format(date, 'an')).toEqual('fa 1 hora');

advanceTo(1000 * 60 * 60 * 8);
vi.setSystemTime(1000 * 60 * 60 * 8);
expect(format(date, 'an')).toEqual('fa 8 horas');

advanceTo(1000 * 60 * 60 * 24);
vi.setSystemTime(1000 * 60 * 60 * 24);
expect(format(date, 'an')).toEqual('fa 1 día');

advanceTo(1000 * 60 * 60 * 24 * 3);
vi.setSystemTime(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'an')).toEqual('fa 3 días');

advanceTo(1000 * 60 * 60 * 24 * 7);
vi.setSystemTime(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'an')).toEqual('fa 1 semana');

advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
vi.setSystemTime(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'an')).toEqual('fa 3 semanas');

advanceTo(1000 * 60 * 60 * 24 * 31);
vi.setSystemTime(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'an')).toEqual('fa 1 mes');

advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
vi.setSystemTime(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'an')).toEqual('fa 4 meses');

advanceTo(1000 * 60 * 60 * 24 * 366);
vi.setSystemTime(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'an')).toEqual('fa 1 anyo');

advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
vi.setSystemTime(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'an')).toEqual('fa 10 anyos');
});
test('time in', () => {
advanceTo(-9 * 1000);
vi.setSystemTime(-9 * 1000);
expect(format(date, 'an')).toEqual("d'aquí a un momento");

advanceTo(-30 * 1000);
vi.setSystemTime(-30 * 1000);
expect(format(date, 'an')).toEqual("d'aquí a 30 segundos");

advanceTo(-1000 * 60);
vi.setSystemTime(-1000 * 60);
expect(format(date, 'an')).toEqual("d'aquí a 1 minuto");

advanceTo(-1000 * 60 * 30);
vi.setSystemTime(-1000 * 60 * 30);
expect(format(date, 'an')).toEqual("d'aquí a 30 minutos");

advanceTo(-1000 * 60 * 60);
vi.setSystemTime(-1000 * 60 * 60);
expect(format(date, 'an')).toEqual("d'aquí a 1 hora");

advanceTo(-1000 * 60 * 60 * 8);
vi.setSystemTime(-1000 * 60 * 60 * 8);
expect(format(date, 'an')).toEqual("d'aquí a 8 horas");

advanceTo(-1000 * 60 * 60 * 24);
vi.setSystemTime(-1000 * 60 * 60 * 24);
expect(format(date, 'an')).toEqual("d'aquí a 1 día");

advanceTo(-1000 * 60 * 60 * 24 * 3);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'an')).toEqual("d'aquí a 3 días");

advanceTo(-1000 * 60 * 60 * 24 * 7);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'an')).toEqual("d'aquí a 1 semana");

advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'an')).toEqual("d'aquí a 3 semanas");

advanceTo(-1000 * 60 * 60 * 24 * 31);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'an')).toEqual("d'aquí a 1 mes");

advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'an')).toEqual("d'aquí a 4 meses");

advanceTo(-1000 * 60 * 60 * 24 * 366);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'an')).toEqual("d'aquí a 1 anyo");

advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
vi.setSystemTime(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'an')).toEqual("d'aquí a 10 anyos");
});
});
Loading
Loading