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
5 changes: 5 additions & 0 deletions .changeset/honest-bananas-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scaleway/use-i18n": minor
---

feat: add format second to formatDate
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ exports[`formatDate > should work with format "numericHour", for date = "new Dat

exports[`formatDate > should work with format "numericHour", for date = "new Date(2020, 1, 13, 16, 28)" and locale "ro" 1`] = `"2020-02-13 16:28"`;

exports[`formatDate > should work with format "second", for date = "2020-02-13T15:28:00.000Z" and locale "de" 1`] = `"13. Februar 2020 um 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "2020-02-13T15:28:00.000Z" and locale "en" 1`] = `"February 13, 2020 at 3:28:00 PM"`;

exports[`formatDate > should work with format "second", for date = "2020-02-13T15:28:00.000Z" and locale "es" 1`] = `"13 de febrero de 2020, 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "2020-02-13T15:28:00.000Z" and locale "fr" 1`] = `"13 février 2020 à 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "2020-02-13T15:28:00.000Z" and locale "ro" 1`] = `"13 februarie 2020 la 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "1581607680000" and locale "de" 1`] = `"13. Februar 2020 um 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "1581607680000" and locale "en" 1`] = `"February 13, 2020 at 3:28:00 PM"`;

exports[`formatDate > should work with format "second", for date = "1581607680000" and locale "es" 1`] = `"13 de febrero de 2020, 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "1581607680000" and locale "fr" 1`] = `"13 février 2020 à 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "1581607680000" and locale "ro" 1`] = `"13 februarie 2020 la 15:28:00"`;

exports[`formatDate > should work with format "second", for date = "new Date(2020, 1, 13, 16, 28)" and locale "de" 1`] = `"13. Februar 2020 um 16:28:00"`;

exports[`formatDate > should work with format "second", for date = "new Date(2020, 1, 13, 16, 28)" and locale "en" 1`] = `"February 13, 2020 at 4:28:00 PM"`;

exports[`formatDate > should work with format "second", for date = "new Date(2020, 1, 13, 16, 28)" and locale "es" 1`] = `"13 de febrero de 2020, 16:28:00"`;

exports[`formatDate > should work with format "second", for date = "new Date(2020, 1, 13, 16, 28)" and locale "fr" 1`] = `"13 février 2020 à 16:28:00"`;

exports[`formatDate > should work with format "second", for date = "new Date(2020, 1, 13, 16, 28)" and locale "ro" 1`] = `"13 februarie 2020 la 16:28:00"`;

exports[`formatDate > should work with format "short", for date = "2020-02-13T15:28:00.000Z" and locale "de" 1`] = `"13. Feb. 2020"`;

exports[`formatDate > should work with format "short", for date = "2020-02-13T15:28:00.000Z" and locale "en" 1`] = `"Feb 13, 2020"`;
Expand Down
2 changes: 1 addition & 1 deletion packages/use-i18n/src/__tests__/formatDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('formatDate', () => {
// @ts-expect-error we check a failing case
formatDate('fr', 1581607680000, 'not a valid format'),
).toThrowError(
'format "not a valid format" should be one of hour, hourOnly, long, short, shortWithoutDay, numeric, numericHour or a valid Intl.DateTimeFormat options object',
'format "not a valid format" should be one of second, hour, hourOnly, long, short, shortWithoutDay, numeric, numericHour or a valid Intl.DateTimeFormat options object',
)
})
})
9 changes: 9 additions & 0 deletions packages/use-i18n/src/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { formatISO, intlFormat } from 'date-fns'

const formatOptions = {
second: {
// Expected output format: 13 February 2025 at 4:28:00
day: 'numeric',
month: 'long',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
},
hour: {
// Expected output format: February 13, 2020, 4:28 PM
day: 'numeric',
Expand Down