Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/web/src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function formatCost(usd: number): string {

export function formatDate(s: string): string {
try {
const date = new Date(s)
const date = Date.parse(s)
if (Number.isNaN(date)) return s
return dateFnsFormat(date, 'MMM d')
} catch {
return s
Expand All @@ -32,8 +33,8 @@ export function formatDate(s: string): string {

export function formatDateTime(s: string): string {
try {
const date = new Date(s)
if (Number.isNaN(date.getTime())) return s
const date = Date.parse(s)
if (Number.isNaN(date)) return s
return dateFnsFormat(date, 'MM/dd/yyyy h:mm:ss a')
} catch {
return s
Expand All @@ -43,8 +44,8 @@ export function formatDateTime(s: string): string {
// 2026-04-13 16:29:29 ν˜•νƒœ
export function formatDateTimeFull(s: string): string {
try {
const date = new Date(s)
if (Number.isNaN(date.getTime())) return s
const date = Date.parse(s)
if (Number.isNaN(date)) return s
return dateFnsFormat(date, 'yyyy-MM-dd HH:mm:ss')
} catch {
return s
Expand All @@ -61,15 +62,17 @@ export function formatRelativeTime(timestamp: string, baseTimestamp: string): st
export function formatRelativeTime(timestamp: string, baseTimestamp?: string): string {
if (baseTimestamp === undefined) {
try {
return formatDistanceToNow(new Date(timestamp), { addSuffix: true, locale: ko })
const date = Date.parse(timestamp)
if (Number.isNaN(date)) return timestamp
return formatDistanceToNow(date, { addSuffix: true, locale: ko })
} catch {
return timestamp
}
}

const timestampDate = new Date(timestamp)
const baseDate = new Date(baseTimestamp)
const diffMs = timestampDate.getTime() - baseDate.getTime()
const timestampDate = Date.parse(timestamp)
const baseDate = Date.parse(baseTimestamp)
const diffMs = timestampDate - baseDate
const totalMinutes = Math.floor(diffMs / 60000)

if (totalMinutes < 60) {
Expand Down
11 changes: 5 additions & 6 deletions packages/web/src/lib/server/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,18 @@ export function parseDateRange(from?: string, to?: string): DateRange {
let toDate: Date

if (from) {
fromDate = new Date(from)
if (isNaN(fromDate.getTime())) {
fromDate = defaultFrom
}
const fromTime = Date.parse(from)
fromDate = isNaN(fromTime) ? defaultFrom : new Date(fromTime)
} else {
fromDate = defaultFrom
}

if (to) {
toDate = new Date(to)
if (isNaN(toDate.getTime())) {
const toTime = Date.parse(to)
if (isNaN(toTime)) {
toDate = now
} else {
toDate = new Date(toTime)
// "2026-04-16" β†’ UTC 00:00:00 μ΄λ―€λ‘œ ν•΄λ‹Ή λ‚ μ§œμ˜ 끝(23:59:59.999)으둜 보정
toDate.setUTCHours(23, 59, 59, 999)
}
Expand Down
Loading