forked from date-fns/date-fns
-
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.
ja-Hira ts migration (date-fns#2857)
- Loading branch information
Showing
8 changed files
with
244 additions
and
193 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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 |
23 changes: 12 additions & 11 deletions
23
src/locale/ja-Hira/_lib/formatLong/index.js → src/locale/ja-Hira/_lib/formatLong/index.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 |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
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,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 |
Oops, something went wrong.