-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0dc976a
commit 964351c
Showing
4 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/sif-common-utils/src/__tests__/intlDateFormat.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { ISODateToDate } from '../'; | ||
import { intlDateFormats } from '../intlDateFormats'; | ||
|
||
describe('intlDateFormat', () => { | ||
const date = ISODateToDate('2020-01-04'); | ||
|
||
it('compact', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.compact).format(date); | ||
expect(result).toEqual('04.01.2020'); | ||
}); | ||
it('dateShortMonthYear', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.dateShortMonthYear).format(date); | ||
expect(result).toEqual('4. jan. 2020'); | ||
}); | ||
it('weekday', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.weekday).format(date); | ||
expect(result).toEqual('lørdag'); | ||
}); | ||
it('weekdayCompactDate', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.weekdayCompactDate).format(date); | ||
expect(result).toEqual('lørdag 04.01.2020'); | ||
}); | ||
it('weekdayDateMonth', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.weekdayDateMonth).format(date); | ||
expect(result).toEqual('lørdag 4. januar'); | ||
}); | ||
it('weekdayDateMonthYear', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.weekdayDateMonthYear).format(date); | ||
expect(result).toEqual('lørdag 4. januar 2020'); | ||
}); | ||
it('weekdayDateShortMonth', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.weekdayDateShortMonth).format(date); | ||
expect(result).toEqual('lørdag 4. jan.'); | ||
}); | ||
it('weekdayDateShortMonthYear', () => { | ||
const result = Intl.DateTimeFormat('nb', intlDateFormats.weekdayDateShortMonthYear).format(date); | ||
expect(result).toEqual('lørdag 4. jan. 2020'); | ||
}); | ||
|
||
describe('nynorsk', () => { | ||
it('weekday', () => { | ||
const result = Intl.DateTimeFormat('nn', intlDateFormats.weekday).format(date); | ||
expect(result).toEqual('laurdag'); | ||
}); | ||
it('weekdayCompactDate', () => { | ||
const result = Intl.DateTimeFormat('nn', intlDateFormats.weekdayCompactDate).format(date); | ||
expect(result).toEqual('laurdag 04.01.2020'); | ||
}); | ||
it('weekdayDateMonth', () => { | ||
const result = Intl.DateTimeFormat('nn', intlDateFormats.weekdayDateMonth).format(date); | ||
expect(result).toEqual('laurdag 4. januar'); | ||
}); | ||
it('weekdayDateMonthYear', () => { | ||
const result = Intl.DateTimeFormat('nn', intlDateFormats.weekdayDateMonthYear).format(date); | ||
expect(result).toEqual('laurdag 4. januar 2020'); | ||
}); | ||
it('weekdayDateShortMonth', () => { | ||
const result = Intl.DateTimeFormat('nn', intlDateFormats.weekdayDateShortMonth).format(date); | ||
expect(result).toEqual('laurdag 4. jan.'); | ||
}); | ||
it('weekdayDateShortMonthYear', () => { | ||
const result = Intl.DateTimeFormat('nn', intlDateFormats.weekdayDateShortMonthYear).format(date); | ||
expect(result).toEqual('laurdag 4. jan. 2020'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { FormatDateOptions } from 'react-intl'; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returns 01.01.2020 | ||
*/ | ||
const compact: FormatDateOptions = { | ||
day: '2-digit', | ||
month: '2-digit', | ||
year: 'numeric', | ||
}; | ||
/** | ||
* | ||
* @param date: Date | ||
* @returns 1. jan. 2021 | ||
*/ | ||
const dateShortMonthYear: FormatDateOptions = { | ||
day: 'numeric', | ||
month: 'short', | ||
year: 'numeric', | ||
}; | ||
/** | ||
* | ||
* @param date: Date | ||
* @returns 1. januar 2021 | ||
*/ | ||
const full: FormatDateOptions = { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
}; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returns fredag | ||
*/ | ||
const weekday: FormatDateOptions = { | ||
weekday: 'long', | ||
}; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returns fredag 01.01.2021 | ||
*/ | ||
const weekdayCompactDate: FormatDateOptions = { | ||
day: '2-digit', | ||
month: '2-digit', | ||
year: 'numeric', | ||
weekday: 'long', | ||
}; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returns fredag 1. jan. 2021 | ||
*/ | ||
const weekdayDateShortMonthYear: FormatDateOptions = { | ||
day: 'numeric', | ||
month: 'short', | ||
year: 'numeric', | ||
weekday: 'long', | ||
}; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returnsfredag 1. januar 2021 | ||
*/ | ||
const weekdayDateMonthYear: FormatDateOptions = { | ||
day: 'numeric', | ||
month: 'long', | ||
year: 'numeric', | ||
weekday: 'long', | ||
}; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returns fredag 1. jan. | ||
*/ | ||
const weekdayDateMonth: FormatDateOptions = { | ||
day: 'numeric', | ||
month: 'long', | ||
weekday: 'long', | ||
}; | ||
|
||
/** | ||
* | ||
* @param date: Date | ||
* @returns fredag 1. januar | ||
*/ | ||
const weekdayDateShortMonth: FormatDateOptions = { | ||
day: 'numeric', | ||
month: 'short', | ||
weekday: 'long', | ||
}; | ||
|
||
export const intlDateFormats: Record<string, FormatDateOptions> = { | ||
compact, | ||
dateShortMonthYear, | ||
full, | ||
weekday, | ||
weekdayCompactDate, | ||
weekdayDateMonth, | ||
weekdayDateMonthYear, | ||
weekdayDateShortMonth, | ||
weekdayDateShortMonthYear, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters