Skip to content

Commit

Permalink
ja-Hira ts migration (date-fns#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
fturmel authored Dec 20, 2021
1 parent d966cd4 commit 9785540
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 193 deletions.
116 changes: 0 additions & 116 deletions src/locale/ja-Hira/_lib/formatDistance/index.js

This file was deleted.

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

type FormatDistanceTokenValue =
| string
| {
one: string
other: string
oneWithSuffix?: string
otherWithSuffix?: string
}

const formatDistanceLocale: FormatDistanceLocale<FormatDistanceTokenValue> = {
lessThanXSeconds: {
one: '1びょうみまん',
other: '{{count}}びょうみまん',
oneWithSuffix: 'やく1びょう',
otherWithSuffix: 'やく{{count}}びょう',
},

xSeconds: {
one: '1びょう',
other: '{{count}}びょう',
},

halfAMinute: '30びょう',

lessThanXMinutes: {
one: '1ぷんみまん',
other: '{{count}}ふんみまん',
oneWithSuffix: 'やく1ぷん',
otherWithSuffix: 'やく{{count}}ふん',
},

xMinutes: {
one: '1ぷん',
other: '{{count}}ふん',
},

aboutXHours: {
one: 'やく1じかん',
other: 'やく{{count}}じかん',
},

xHours: {
one: '1じかん',
other: '{{count}}じかん',
},

xDays: {
one: '1にち',
other: '{{count}}にち',
},

aboutXWeeks: {
one: 'やく1しゅうかん',
other: 'やく{{count}}しゅうかん',
},

xWeeks: {
one: '1しゅうかん',
other: '{{count}}しゅうかん',
},

aboutXMonths: {
one: 'やく1かげつ',
other: 'やく{{count}}かげつ',
},

xMonths: {
one: '1かげつ',
other: '{{count}}かげつ',
},

aboutXYears: {
one: 'やく1ねん',
other: 'やく{{count}}ねん',
},

xYears: {
one: '1ねん',
other: '{{count}}ねん',
},

overXYears: {
one: '1ねんいじょう',
other: '{{count}}ねんいじょう',
},

almostXYears: {
one: '1ねんちかく',
other: '{{count}}ねんちかく',
},
}

const formatDistance: FormatDistanceFn = (token, count, options) => {
options = options || {}

let result

const tokenValue = formatDistanceLocale[token]
if (typeof tokenValue === 'string') {
result = tokenValue
} else if (count === 1) {
if (options.addSuffix && tokenValue.oneWithSuffix) {
result = tokenValue.oneWithSuffix
} else {
result = tokenValue.one
}
} else {
if (options.addSuffix && tokenValue.otherWithSuffix) {
result = tokenValue.otherWithSuffix.replace('{{count}}', String(count))
} else {
result = tokenValue.other.replace('{{count}}', String(count))
}
}

if (options.addSuffix) {
if (options.comparison && options.comparison > 0) {
return result + 'あと'
} else {
return result + 'まえ'
}
}

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: 'yねんMがつdにちEEEE',
long: 'yねんMがつdにち',
medium: 'y/MM/dd',
short: 'y/MM/dd'
short: 'y/MM/dd',
}

var timeFormats = {
const timeFormats = {
full: 'Hじmmふんssびょう zzzz',
long: 'H:mm:ss z',
medium: 'H:mm:ss',
short: 'H:mm'
short: 'H:mm',
}

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

This file was deleted.

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

const formatRelativeLocale = {
lastWeek: 'せんしゅうのeeeeのp',
yesterday: 'きのうのp',
today: 'きょうのp',
tomorrow: 'あしたのp',
nextWeek: 'よくしゅうのeeeeのp',
other: 'P',
}

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

export default formatRelative
Loading

0 comments on commit 9785540

Please sign in to comment.