Skip to content

Commit

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

This file was deleted.

112 changes: 112 additions & 0 deletions src/locale/id/_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: 'kurang dari 1 detik',
other: 'kurang dari {{count}} detik',
},

xSeconds: {
one: '1 detik',
other: '{{count}} detik',
},

halfAMinute: 'setengah menit',

lessThanXMinutes: {
one: 'kurang dari 1 menit',
other: 'kurang dari {{count}} menit',
},

xMinutes: {
one: '1 menit',
other: '{{count}} menit',
},

aboutXHours: {
one: 'sekitar 1 jam',
other: 'sekitar {{count}} jam',
},

xHours: {
one: '1 jam',
other: '{{count}} jam',
},

xDays: {
one: '1 hari',
other: '{{count}} hari',
},

aboutXWeeks: {
one: 'sekitar 1 minggu',
other: 'sekitar {{count}} minggu',
},

xWeeks: {
one: '1 minggu',
other: '{{count}} minggu',
},

aboutXMonths: {
one: 'sekitar 1 bulan',
other: 'sekitar {{count}} bulan',
},

xMonths: {
one: '1 bulan',
other: '{{count}} bulan',
},

aboutXYears: {
one: 'sekitar 1 tahun',
other: 'sekitar {{count}} tahun',
},

xYears: {
one: '1 tahun',
other: '{{count}} tahun',
},

overXYears: {
one: 'lebih dari 1 tahun',
other: 'lebih dari {{count}} tahun',
},

almostXYears: {
one: 'hampir 1 tahun',
other: 'hampir {{count}} tahun',
},
}

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 'dalam waktu ' + result
} else {
return result + ' yang lalu'
}
}

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, d MMMM yyyy',
long: 'd MMMM yyyy',
medium: 'd MMM yyyy',
short: 'd/M/yyyy'
short: 'd/M/yyyy',
}

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

var dateTimeFormats = {
const dateTimeFormats = {
full: "{{date}} 'pukul' {{time}}",
long: "{{date}} 'pukul' {{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/id/_lib/formatRelative/index.js

This file was deleted.

15 changes: 15 additions & 0 deletions src/locale/id/_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: "eeee 'lalu pukul' p",
yesterday: "'Kemarin pukul' p",
today: "'Hari ini pukul' p",
tomorrow: "'Besok pukul' p",
nextWeek: "eeee 'pukul' p",
other: 'P',
}

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

export default formatRelative
Loading

0 comments on commit d966cd4

Please sign in to comment.