Skip to content

Commit

Permalink
is locale TS migration (date-fns#2854)
Browse files Browse the repository at this point in the history
  • Loading branch information
fturmel authored Dec 20, 2021
1 parent 5e649a8 commit 5f6af88
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 272 deletions.
101 changes: 0 additions & 101 deletions src/locale/is/_lib/formatDistance/index.js

This file was deleted.

112 changes: 112 additions & 0 deletions src/locale/is/_lib/formatDistance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import type { FormatDistanceFn, FormatDistanceLocale } from '../../../types'

type FormatDistanceTokenValue =
| string
| {
one: string
other: string
}

const formatDistanceLocale: FormatDistanceLocale<FormatDistanceTokenValue> = {
lessThanXSeconds: {
one: 'minna en 1 sekúnda',
other: 'minna en {{count}} sekúndur',
},

xSeconds: {
one: '1 sekúnda',
other: '{{count}} sekúndur',
},

halfAMinute: 'hálf mínúta',

lessThanXMinutes: {
one: 'minna en 1 mínúta',
other: 'minna en {{count}} mínútur',
},

xMinutes: {
one: '1 mínúta',
other: '{{count}} mínútur',
},

aboutXHours: {
one: 'u.þ.b. 1 klukkustund',
other: 'u.þ.b. {{count}} klukkustundir',
},

xHours: {
one: '1 klukkustund',
other: '{{count}} klukkustundir',
},

xDays: {
one: '1 dagur',
other: '{{count}} dagar',
},

aboutXWeeks: {
one: 'um viku',
other: 'um {{count}} vikur',
},

xWeeks: {
one: '1 viku',
other: '{{count}} vikur',
},

aboutXMonths: {
one: 'u.þ.b. 1 mánuður',
other: 'u.þ.b. {{count}} mánuðir',
},

xMonths: {
one: '1 mánuður',
other: '{{count}} mánuðir',
},

aboutXYears: {
one: 'u.þ.b. 1 ár',
other: 'u.þ.b. {{count}} ár',
},

xYears: {
one: '1 ár',
other: '{{count}} ár',
},

overXYears: {
one: 'meira en 1 ár',
other: 'meira en {{count}} ár',
},

almostXYears: {
one: 'næstum 1 ár',
other: 'næstum {{count}} ár',
},
}

const formatDistance: FormatDistanceFn = (token, count, options) => {
let result

const tokenValue = formatDistanceLocale[token]
if (typeof tokenValue === 'string') {
result = tokenValue
} else if (count === 1) {
result = tokenValue.one
} else {
result = tokenValue.other.replace('{{count}}', count.toString())
}

if (options?.addSuffix) {
if (options.comparison && options.comparison > 0) {
return 'í ' + result
} else {
return result + ' síðan'
}
}

return result
}

export default formatDistance
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import type { FormatLong } from '../../../types'
import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index'

var dateFormats = {
const dateFormats = {
full: 'EEEE, do MMMM y',
long: 'do MMMM y',
medium: 'do MMM y',
short: 'd.MM.y'
short: 'd.MM.y',
}

var timeFormats = {
const timeFormats = {
full: "'kl'. HH:mm:ss zzzz",
long: 'HH:mm:ss z',
medium: 'HH:mm:ss',
short: 'HH:mm'
short: 'HH:mm',
}

var dateTimeFormats = {
const dateTimeFormats = {
full: "{{date}} 'kl.' {{time}}",
long: "{{date}} 'kl.' {{time}}",
medium: '{{date}} {{time}}',
short: '{{date}} {{time}}'
short: '{{date}} {{time}}',
}

var formatLong = {
const formatLong: FormatLong = {
date: buildFormatLongFn({
formats: dateFormats,
defaultWidth: 'full'
defaultWidth: 'full',
}),

time: buildFormatLongFn({
formats: timeFormats,
defaultWidth: 'full'
defaultWidth: 'full',
}),

dateTime: buildFormatLongFn({
formats: dateTimeFormats,
defaultWidth: 'full'
})
defaultWidth: 'full',
}),
}

export default formatLong
12 changes: 0 additions & 12 deletions src/locale/is/_lib/formatRelative/index.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/locale/is/_lib/formatRelative/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { FormatRelativeFn } from '../../../types'

const formatRelativeLocale = {
lastWeek: "'síðasta' dddd 'kl.' p",
yesterday: "'í gær kl.' p",
today: "'í dag kl.' p",
tomorrow: "'á morgun kl.' p",
nextWeek: "dddd 'kl.' p",
other: 'P',
}

const formatRelative: FormatRelativeFn = (token, _date, _baseDate, _options) =>
formatRelativeLocale[token]

export default formatRelative
Loading

0 comments on commit 5f6af88

Please sign in to comment.