style: fix timezone.ts indentation

This commit is contained in:
2026-04-21 01:22:00 +02:00
parent 435656a4cc
commit 1ceca3bd9e

View File

@@ -2,13 +2,13 @@ export {}
const jstOffsetMinutes = 9 * 60 const jstOffsetMinutes = 9 * 60
type ParsedBroadcast = { type ParsedBroadcast = {
day: string day: string
hour: number hour: number
minute: number minute: number
} }
const parseBroadcastTime = (value: string | null): { hour: number; minute: number } | null => { const parseBroadcastTime = (value: string | null): { hour: number; minute: number } | null => {
if (!value || typeof value !== 'string') { if (!value || typeof value !== 'string') {
return null return null
} }
@@ -25,18 +25,18 @@ const jstOffsetMinutes = 9 * 60
} }
return { hour, minute } return { hour, minute }
} }
const isJstTimezone = (timezone: string | null): boolean => { const isJstTimezone = (timezone: string | null): boolean => {
if (!timezone) { if (!timezone) {
return true return true
} }
const normalized = timezone.trim().toLowerCase() const normalized = timezone.trim().toLowerCase()
return normalized === 'asia/tokyo' || normalized === 'jst' return normalized === 'asia/tokyo' || normalized === 'jst'
} }
const parseFromStructuredAttrs = (node: Element): ParsedBroadcast | null => { const parseFromStructuredAttrs = (node: Element): ParsedBroadcast | null => {
const day = node.getAttribute('data-broadcast-day') const day = node.getAttribute('data-broadcast-day')
const time = node.getAttribute('data-broadcast-time') const time = node.getAttribute('data-broadcast-time')
const timezone = node.getAttribute('data-broadcast-timezone') const timezone = node.getAttribute('data-broadcast-timezone')
@@ -51,9 +51,9 @@ const jstOffsetMinutes = 9 * 60
} }
return { day: day.trim(), hour: parsedTime.hour, minute: parsedTime.minute } return { day: day.trim(), hour: parsedTime.hour, minute: parsedTime.minute }
} }
const parseBroadcast = (text: string | null): ParsedBroadcast | null => { const parseBroadcast = (text: string | null): ParsedBroadcast | null => {
if (!text || typeof text !== 'string') { if (!text || typeof text !== 'string') {
return null return null
} }
@@ -76,9 +76,9 @@ const jstOffsetMinutes = 9 * 60
} }
return { day, hour, minute } return { day, hour, minute }
} }
const normalizeDay = (day: string): number | null => { const normalizeDay = (day: string): number | null => {
const key = day.trim().toLowerCase().replace(/s$/, '') const key = day.trim().toLowerCase().replace(/s$/, '')
const days: Record<string, number> = { const days: Record<string, number> = {
mon: 1, mon: 1,
@@ -105,9 +105,9 @@ const jstOffsetMinutes = 9 * 60
} }
return days[key] return days[key]
} }
const convertToLocal = (parsed: ParsedBroadcast, localOffsetMinutes: number): string | null => { const convertToLocal = (parsed: ParsedBroadcast, localOffsetMinutes: number): string | null => {
const sourceMinutes = parsed.hour * 60 + parsed.minute const sourceMinutes = parsed.hour * 60 + parsed.minute
const diff = jstOffsetMinutes - localOffsetMinutes const diff = jstOffsetMinutes - localOffsetMinutes
const localTotal = sourceMinutes - diff const localTotal = sourceMinutes - diff
@@ -127,9 +127,9 @@ const jstOffsetMinutes = 9 * 60
const time = `${localHour.toString().padStart(2, '0')}:${localMinute.toString().padStart(2, '0')}` const time = `${localHour.toString().padStart(2, '0')}:${localMinute.toString().padStart(2, '0')}`
return `${localDay} at ${time} (Local)` return `${localDay} at ${time} (Local)`
} }
const nextAiringUTC = (parsed: ParsedBroadcast): Date | null => { const nextAiringUTC = (parsed: ParsedBroadcast): Date | null => {
const targetDay = normalizeDay(parsed.day) const targetDay = normalizeDay(parsed.day)
if (targetDay === null) { if (targetDay === null) {
return null return null
@@ -149,9 +149,9 @@ const jstOffsetMinutes = 9 * 60
const minuteDelta = dayDelta * 1440 + (targetMinuteOfDay - currentMinuteOfDay) const minuteDelta = dayDelta * 1440 + (targetMinuteOfDay - currentMinuteOfDay)
return new Date(now.getTime() + minuteDelta * 60 * 1000) return new Date(now.getTime() + minuteDelta * 60 * 1000)
} }
const formatRelative = (value: number, unit: Intl.RelativeTimeFormatUnit): string => { const formatRelative = (value: number, unit: Intl.RelativeTimeFormatUnit): string => {
if (typeof Intl !== 'undefined' && typeof Intl.RelativeTimeFormat === 'function') { if (typeof Intl !== 'undefined' && typeof Intl.RelativeTimeFormat === 'function') {
const formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' }) const formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' })
return formatter.format(value, unit) return formatter.format(value, unit)
@@ -159,9 +159,9 @@ const jstOffsetMinutes = 9 * 60
const suffix = value === 1 ? unit : `${unit}s` const suffix = value === 1 ? unit : `${unit}s`
return `in ${value} ${suffix}` return `in ${value} ${suffix}`
} }
const relativeText = (target: Date): string => { const relativeText = (target: Date): string => {
const diffMs = target.getTime() - Date.now() const diffMs = target.getTime() - Date.now()
if (diffMs <= 0) { if (diffMs <= 0) {
return 'soon' return 'soon'
@@ -179,18 +179,18 @@ const jstOffsetMinutes = 9 * 60
const days = Math.ceil(hours / 24) const days = Math.ceil(hours / 24)
return formatRelative(days, 'day') return formatRelative(days, 'day')
} }
const localDateTimeText = (date: Date): string => { const localDateTimeText = (date: Date): string => {
const formatter = new Intl.DateTimeFormat(undefined, { const formatter = new Intl.DateTimeFormat(undefined, {
weekday: 'short', weekday: 'short',
hour: '2-digit', hour: '2-digit',
minute: '2-digit', minute: '2-digit',
}) })
return formatter.format(date) return formatter.format(date)
} }
const updateNextAiring = (node: Element, parsed: ParsedBroadcast): void => { const updateNextAiring = (node: Element, parsed: ParsedBroadcast): void => {
const card = node.closest('[data-notification-content]') const card = node.closest('[data-notification-content]')
if (!card) { if (!card) {
return return
@@ -208,9 +208,9 @@ const jstOffsetMinutes = 9 * 60
} }
nextNode.textContent = `Next episode ${relativeText(nextDate)} (${localDateTimeText(nextDate)})` nextNode.textContent = `Next episode ${relativeText(nextDate)} (${localDateTimeText(nextDate)})`
} }
const updateNode = (node: Element, localOffsetMinutes: number): void => { const updateNode = (node: Element, localOffsetMinutes: number): void => {
const card = node.closest('[data-notification-content]') const card = node.closest('[data-notification-content]')
const nextNode = card ? card.querySelector('[data-next-airing]') : null const nextNode = card ? card.querySelector('[data-next-airing]') : null
@@ -234,13 +234,13 @@ const jstOffsetMinutes = 9 * 60
node.textContent = converted node.textContent = converted
updateNextAiring(node, parsed) updateNextAiring(node, parsed)
} }
const updateAll = (): void => { const updateAll = (): void => {
const localOffsetMinutes = -new Date().getTimezoneOffset() const localOffsetMinutes = -new Date().getTimezoneOffset()
const nodes = document.querySelectorAll('[data-jst-text]') const nodes = document.querySelectorAll('[data-jst-text]')
nodes.forEach((node: Element): void => updateNode(node, localOffsetMinutes)) nodes.forEach((node: Element): void => updateNode(node, localOffsetMinutes))
} }
const initTimezoneConversion = (): void => { const initTimezoneConversion = (): void => {
document.addEventListener('DOMContentLoaded', updateAll) document.addEventListener('DOMContentLoaded', updateAll)