admin/lib/bookingPayment.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

20 lines
730 B
TypeScript

type BookingExpiresAt = string | Date | Record<string, unknown> | null | undefined
const bookingExpiresAtMs = (expiresAt: BookingExpiresAt): number | null => {
if (expiresAt == null) return null
if (typeof expiresAt === 'string' || expiresAt instanceof Date) {
const ms = new Date(expiresAt).getTime()
return Number.isNaN(ms) ? null : ms
}
return null
}
/** Whether a pending_payment booking's hold window has passed (client clock). */
export const isBookingPaymentExpired = (booking: { status: string; expiresAt?: BookingExpiresAt }): boolean => {
const expiresAtMs = bookingExpiresAtMs(booking.expiresAt)
return booking.status === 'pending_payment' && expiresAtMs != null && expiresAtMs <= Date.now()
}