Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hustcc/timeago.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Sep 8, 2020
2 parents 924e782 + 5d0a961 commit 7ebf670
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ or import with `script` tag in html file and access global variable `timeago`.
format('2016-06-12', 'en_US');
```

## CDN

Alternatively to NPM, you can also use a CDN which will reflect the latest version as soon as it is published to npm.

```html
<script src="//unpkg.com/timeago.js"></script>
```

## API

Expand Down
103 changes: 103 additions & 0 deletions __tests__/lang/tk.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import tk from '../../src/lang/tk';

register('tk', tk);

let date = new Date();

beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('tk', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'tk')).toEqual('biraz öň');

advanceTo(30 * 1000);
expect(format(date, 'tk')).toEqual('30 sekunt öň');

advanceTo(1000 * 60);
expect(format(date, 'tk')).toEqual('1 minut öň');

advanceTo(1000 * 60 * 30);
expect(format(date, 'tk')).toEqual('30 minut öň');

advanceTo(1000 * 60 * 60);
expect(format(date, 'tk')).toEqual('1 sagat öň');

advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'tk')).toEqual('8 sagat öň');

advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'tk')).toEqual('1 gün öň');

advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'tk')).toEqual('3 gün öň');

advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'tk')).toEqual('1 hepde öň');

advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'tk')).toEqual('3 hepde öň');

advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'tk')).toEqual('1 aý öň');

advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'tk')).toEqual('4 aý öň');

advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'tk')).toEqual('1 ýyl öň');

advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'tk')).toEqual('10 ýyl öň');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'tk')).toEqual('şuwagt');

advanceTo(-30 * 1000);
expect(format(date, 'tk')).toEqual('30 sekuntdan');

advanceTo(-1000 * 60);
expect(format(date, 'tk')).toEqual('1 minutdan');

advanceTo(-1000 * 60 * 30);
expect(format(date, 'tk')).toEqual('30 minutdan');

advanceTo(-1000 * 60 * 60);
expect(format(date, 'tk')).toEqual('1 sagatdan');

advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'tk')).toEqual('8 sagatdan');

advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'tk')).toEqual('1 günden');

advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'tk')).toEqual('3 günden');

advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'tk')).toEqual('1 hepdeden');

advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'tk')).toEqual('3 hepdeden');

advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'tk')).toEqual('1 aýdan');

advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'tk')).toEqual('4 aýdan');

advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'tk')).toEqual('1 ýyldan');

advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'tk')).toEqual('10 ýyldan');
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"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",
"unpkg": "dist/timeago.min.js",
"browser": "dist/timeago.min.js",
"files": [
"lib",
"esm",
Expand Down
9 changes: 9 additions & 0 deletions src/lang/tk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const TK = ['sekunt', 'minut', 'sagat', 'gün', 'hepde', 'aý', 'ýyl'];
function getSuffix(unit: string): string {
return unit.match(/[aouy]/) ? 'dan' : 'den';
}
export default function(diff: number, idx: number): [string, string] {
if (idx === 0) return ['biraz öň', 'şuwagt'];
const unit = TK[Math.floor(idx / 2)];
return [`${diff} ${unit} öň`, `${diff} ${unit}${getSuffix(unit)}`];
}

0 comments on commit 7ebf670

Please sign in to comment.