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

feat: add localized formats plugin #11

Merged
merged 2 commits into from
Jan 31, 2023
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
2 changes: 2 additions & 0 deletions src/dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import quarterOfYear from 'dayjs/plugin/quarterOfYear';
import relativeTime from 'dayjs/plugin/relativeTime';
import timezone from 'dayjs/plugin/timezone';
import utc from 'dayjs/plugin/utc';
import localizedFormat from 'dayjs/plugin/localizedFormat';
import updateLocale from 'dayjs/plugin/updateLocale';

dayjs.extend(arraySupport);
Expand All @@ -17,6 +18,7 @@ dayjs.extend(quarterOfYear);
dayjs.extend(relativeTime);
dayjs.extend(timezone);
dayjs.extend(utc);
dayjs.extend(localizedFormat);
dayjs.extend(updateLocale);
// the modifications made in objectSupport would preserve other plugins behavior
// but not vice versa, therefore it should come last
Expand Down
14 changes: 14 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ describe('Public API', () => {
it('year quarters are supported', () => {
expect(date.startOf('Q').format('YYYY-MM-DD')).toBe('2000-01-01');
});

it('localized formats are supported', () => {
expect(date.locale('en').format('L')).toBe('02/02/2000');
expect(date.locale('ru').format('L')).toBe('02.02.2000');

expect(date.locale('en').format('LL')).toBe('February 2, 2000');
expect(date.locale('ru').format('LL')).toBe('2 февраля 2000 г.');

expect(date.locale('en').format('LT')).toBe('12:00 AM');
expect(date.locale('ru').format('LT')).toBe('0:00');

expect(date.locale('en').format('LTS')).toBe('12:00:00 AM');
expect(date.locale('ru').format('LTS')).toBe('0:00:00');
});
});