このコミットが含まれているのは:
2026-10-26 12:19:43 +09:00
コミット 3e8f209542
31個のファイルの変更、1676行の追加、394行の削除
+15 -11
ファイルの表示
@@ -17,24 +17,26 @@ export const cn = (...inputs: ClassValue[]) => twMerge (clsx (...inputs))
type DatePrecision = 'month' | 'day' | 'hour' | 'minute' | 'second' | null
const dateFormatters = new Map<DatePrecision, Intl.DateTimeFormat> ()
let ainuDateFormatter: Intl.DateTimeFormat | null = null
const dateFormatters = new Map<string, Intl.DateTimeFormat> ()
const ainuDateFormatters = new Map<string, Intl.DateTimeFormat> ()
const formatDateString = (
date: Date,
unknown: DatePrecision,
locale: LocaleCode,
timeZone = 'Asia/Tokyo',
): string => {
const key = `${timeZone}/${unknown}`
if (Number.isNaN (date.getTime ()))
return date.toString ()
if (locale === 'ja')
{
if (!dateFormatters.has (unknown))
if (!dateFormatters.has (key))
{
dateFormatters.set (unknown, new Intl.DateTimeFormat ('ja-JP-u-ca-japanese', {
dateFormatters.set (key, new Intl.DateTimeFormat ('ja-JP-u-ca-japanese', {
era: 'long', year: 'numeric',
timeZone: 'Asia/Tokyo',
timeZone,
month: unknown === 'month' ? undefined : 'long',
day: unknown != null && ['month', 'day'].includes (unknown) ? undefined : 'numeric',
weekday: unknown != null && ['month', 'day'].includes (unknown) ? undefined : 'short',
@@ -42,14 +44,15 @@ const formatDateString = (
minute: unknown == null || unknown === 'second' ? 'numeric' : undefined,
second: unknown == null ? 'numeric' : undefined }))
}
return dateFormatters.get (unknown)!.format (date)
return dateFormatters.get (key)!.format (date)
}
ainuDateFormatter ??= new Intl.DateTimeFormat ('en-CA', {
if (!ainuDateFormatters.has (timeZone))
ainuDateFormatters.set (timeZone, new Intl.DateTimeFormat ('en-CA', {
year: 'numeric', month: '2-digit', day: '2-digit',
timeZone: 'Asia/Tokyo',
timeZone,
hour: '2-digit', minute: '2-digit', second: '2-digit',
hourCycle: 'h23' })
const parts = ainuDateFormatter.formatToParts (date)
hourCycle: 'h23' }))
const parts = ainuDateFormatters.get (timeZone)!.formatToParts (date)
const part = (type: string) => parts.find (entry => entry.type === type)?.value ?? ''
const omitDay = unknown != null && ['month', 'day'].includes (unknown)
const dateParts = [part ('year'),
@@ -76,7 +79,8 @@ export const localisedDateString = (
value: string | Date,
locale: LocaleCode,
unknown: DatePrecision = null,
): string => dateString (value, unknown, locale)
timeZone?: string,
): string => formatDateString (toDate (value), unknown, locale, timeZone)
export const originalCreatedAtString = (