46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
export function formatScheduledDate(value, options = {}) {
|
|
if (!value) return 'Not scheduled'
|
|
|
|
const date = new Date(value)
|
|
if (Number.isNaN(date.getTime())) return 'Not scheduled'
|
|
|
|
try {
|
|
return date.toLocaleString(undefined, {
|
|
month: 'short',
|
|
day: 'numeric',
|
|
...(options.includeYear === false ? {} : { year: 'numeric' }),
|
|
hour: 'numeric',
|
|
minute: '2-digit',
|
|
...(options.timeZone ? { timeZone: options.timeZone } : {}),
|
|
})
|
|
} catch {
|
|
return date.toLocaleString()
|
|
}
|
|
}
|
|
|
|
export function formatReleaseCountdown(value, nowMs = Date.now()) {
|
|
if (!value) return 'Not scheduled'
|
|
|
|
const releaseDate = new Date(value)
|
|
if (Number.isNaN(releaseDate.getTime())) return 'Not scheduled'
|
|
|
|
const remainingMs = releaseDate.getTime() - nowMs
|
|
|
|
if (remainingMs <= 0) {
|
|
return 'Releasing now'
|
|
}
|
|
|
|
const totalSeconds = Math.floor(remainingMs / 1000)
|
|
const days = Math.floor(totalSeconds / 86400)
|
|
const hours = Math.floor((totalSeconds % 86400) / 3600)
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
const seconds = totalSeconds % 60
|
|
const parts = []
|
|
|
|
if (days > 0) parts.push(`${days}d`)
|
|
if (days > 0 || hours > 0) parts.push(`${hours}h`)
|
|
if (days > 0 || hours > 0 || minutes > 0) parts.push(`${minutes}m`)
|
|
if (days === 0) parts.push(`${seconds}s`)
|
|
|
|
return `In ${parts.join(' ')}`
|
|
} |