Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added icelandic, along with tests #225

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ esm
dist

timeago.full.min.js
timeago.min.js
timeago.min.js
olitomas marked this conversation as resolved.
Show resolved Hide resolved
113 changes: 113 additions & 0 deletions __tests__/lang/is.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Created by hustcc on 18/5/24.
* Contact: [email protected]
*/
olitomas marked this conversation as resolved.
Show resolved Hide resolved
import { advanceTo, clear } from 'jest-date-mock';
import { format, register } from '../../src';
import is from '../../src/lang/is';

register('is', is);

let date = new Date();

beforeEach(() => {
advanceTo(0);
date = new Date();
});
afterEach(() => {
clear();
});
describe('is', () => {
test('time ago', () => {
advanceTo(9 * 1000);
expect(format(date, 'is')).toEqual('rétt í þessu');

advanceTo(30 * 1000);
expect(format(date, 'is')).toEqual('30 sekúndum síðan');

advanceTo(1000 * 60);
expect(format(date, 'is')).toEqual('1 mínútu síðan');

advanceTo(1000 * 60 * 30);
expect(format(date, 'is')).toEqual('30 mínútum síðan');

advanceTo(1000 * 60 * 60);
expect(format(date, 'is')).toEqual('1 klukkutíma síðan');

advanceTo(1000 * 60 * 60 * 8);
expect(format(date, 'is')).toEqual('8 klukkutímum síðan');

advanceTo(1000 * 60 * 60 * 24);
expect(format(date, 'is')).toEqual('1 degi síðan');

advanceTo(1000 * 60 * 60 * 24 * 3);
expect(format(date, 'is')).toEqual('3 dögum síðan');

advanceTo(1000 * 60 * 60 * 24 * 7);
expect(format(date, 'is')).toEqual('1 viku síðan');

advanceTo(1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'is')).toEqual('3 vikum síðan');

advanceTo(1000 * 60 * 60 * 24 * 31);
expect(format(date, 'is')).toEqual('1 mánuði síðan');

advanceTo(1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'is')).toEqual('4 mánuðum síðan');

advanceTo(1000 * 60 * 60 * 24 * 366);
expect(format(date, 'is')).toEqual('1 ári síðan');

advanceTo(1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'is')).toEqual('10 árum síðan');
});
test('time in', () => {
advanceTo(-9 * 1000);
expect(format(date, 'is')).toEqual('núna');

advanceTo(-30 * 1000);
expect(format(date, 'is')).toEqual('eftir 30 sekúndur');

advanceTo(-21 * 1000);
expect(format(date, 'is')).toEqual('eftir 21 sekúndu');

advanceTo(-1000 * 60);
expect(format(date, 'is')).toEqual('eftir 1 mínútu');

advanceTo(-1000 * 60 * 30);
expect(format(date, 'is')).toEqual('eftir 30 mínútur');

advanceTo(-1000 * 60 * 31);
expect(format(date, 'is')).toEqual('eftir 31 mínútu');

advanceTo(-1000 * 60 * 60);
expect(format(date, 'is')).toEqual('eftir 1 klukkutíma');

advanceTo(-1000 * 60 * 60 * 8);
expect(format(date, 'is')).toEqual('eftir 8 klukkutíma');

advanceTo(-1000 * 60 * 60 * 24);
expect(format(date, 'is')).toEqual('eftir 1 dag');

advanceTo(-1000 * 60 * 60 * 24 * 3);
expect(format(date, 'is')).toEqual('eftir 3 daga');

advanceTo(-1000 * 60 * 60 * 24 * 7);
expect(format(date, 'is')).toEqual('eftir 1 viku');

advanceTo(-1000 * 60 * 60 * 24 * 7 * 3);
expect(format(date, 'is')).toEqual('eftir 3 vikur');

advanceTo(-1000 * 60 * 60 * 24 * 31);
expect(format(date, 'is')).toEqual('eftir 1 mánuð');

advanceTo(-1000 * 60 * 60 * 24 * 31 * 4);
expect(format(date, 'is')).toEqual('eftir 4 mánuði');

advanceTo(-1000 * 60 * 60 * 24 * 366);
expect(format(date, 'is')).toEqual('eftir 1 ár');

advanceTo(-1000 * 60 * 60 * 24 * 366 * 10);
expect(format(date, 'is')).toEqual('eftir 10 ár');
});
});
22 changes: 22 additions & 0 deletions src/lang/is.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const is = ['sekúnd', 'mínút', 'klukkutím', 'd', 'vik', 'mánuð', 'ár'];
const plural_in = ['ur', 'ur', 'a', 'aga', 'ur', 'i', ''];
const plural_ago = ['um', 'um', 'um', 'ögum', 'um', 'um', 'um'];

const singular_in = ['u', 'u', 'a', 'ag', 'u', '', ''];
const singular_ago = ['u', 'u', 'a', 'egi', 'u', 'i', 'i'];

export default function(diff: number, idx: number): [string, string] {
if (idx === 0) return ['rétt í þessu', 'núna'];
const is_indx = Math.floor(idx / 2);
const unit = is[is_indx];
let unit_in, unit_ago;
if (diff % 10 === 1 && diff !== 11) {
unit_in = singular_in[is_indx];
unit_ago = singular_ago[is_indx];
} else {
unit_in = plural_in[is_indx];
unit_ago = plural_ago[is_indx];
}

return [`${diff} ${unit + unit_ago} síðan`, `eftir ${diff} ${unit + unit_in}`];
}