diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Header/Actions/helpers.ts b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Header/Actions/helpers.ts index 7df5288bb..fe7cb78c7 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Header/Actions/helpers.ts +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Header/Actions/helpers.ts @@ -2,7 +2,7 @@ import { dt } from "@/lib/dt" import type { DateTime } from "ics" -export function generateDateTime(d: Date): DateTime { +export function generateDateTime(d: string): DateTime { const _d = dt(d).utc() return [ _d.year(), diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Form/NewDates/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Form/NewDates/index.tsx index b2152a0d9..635af552b 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Form/NewDates/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/ChangeDates/Steps/Form/NewDates/index.tsx @@ -20,8 +20,8 @@ import useLang from "@/hooks/useLang" import styles from "./newDates.module.css" interface NewDatesProps { - checkInDate: Date - checkOutDate: Date + checkInDate: string + checkOutDate: string } export default function NewDates({ checkInDate, checkOutDate }: NewDatesProps) { diff --git a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/utils.ts b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/utils.ts index 42cfb4097..5162f0410 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/utils.ts +++ b/apps/scandic-web/components/HotelReservation/MyStay/ReferenceCard/Actions/NotCancelled/ManageStay/Actions/utils.ts @@ -1,6 +1,6 @@ import { dt } from "@/lib/dt" -export function dateHasPassed(date: Date, time: string) { +export function dateHasPassed(date: string, time: string) { const hour = dt(time, "HH:mm").hour() const minute = dt(time, "HH:mm").minute() return dt(date).hour(hour).minute(minute).isBefore(dt(), "minutes") diff --git a/apps/scandic-web/server/routers/booking/output.ts b/apps/scandic-web/server/routers/booking/output.ts index 5c2e88887..dedcbd9a6 100644 --- a/apps/scandic-web/server/routers/booking/output.ts +++ b/apps/scandic-web/server/routers/booking/output.ts @@ -1,6 +1,7 @@ import { z } from "zod" import { BookingStatusEnum, ChildBedTypeEnum } from "@/constants/booking" +import { dt } from "@/lib/dt" import { calculateRefId } from "@/utils/refId" import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator" @@ -208,8 +209,8 @@ export const bookingConfirmationSchema = z adults: z.number().int(), ancillary: ancillarySchema, cancelationNumber: z.string().nullable().default(""), - checkInDate: z.date({ coerce: true }), - checkOutDate: z.date({ coerce: true }), + checkInDate: z.string().refine((val) => dt(val).isValid()), + checkOutDate: z.string().refine((val) => dt(val).isValid()), childBedPreferences: z.array(childBedPreferencesSchema).default([]), childrenAges: z.array(z.number().int()).default([]), canChangeDate: z.boolean(), @@ -226,7 +227,7 @@ export const bookingConfirmationSchema = z .nullish(), computedReservationStatus: z.string().nullable().default(""), confirmationNumber: nullableStringValidator, - createDateTime: z.date({ coerce: true }), + createDateTime: z.string().refine((val) => dt(val).isValid()), currencyCode: z.nativeEnum(CurrencyEnum), guest: guestSchema, linkedReservations: nullableArrayObjectValidator( diff --git a/apps/scandic-web/types/providers/booking-confirmation.ts b/apps/scandic-web/types/providers/booking-confirmation.ts index 1cfc7ee96..b72ceacd6 100644 --- a/apps/scandic-web/types/providers/booking-confirmation.ts +++ b/apps/scandic-web/types/providers/booking-confirmation.ts @@ -6,9 +6,9 @@ export interface BookingConfirmationProviderProps extends React.PropsWithChildren { bookingCode: string | null currencyCode: CurrencyEnum - fromDate: Date + fromDate: string roomCategories: RoomCategories rooms: (Room | null)[] - toDate: Date + toDate: string vat: number } diff --git a/apps/scandic-web/types/stores/booking-confirmation.ts b/apps/scandic-web/types/stores/booking-confirmation.ts index 7d99f95cc..34fa1e8f5 100644 --- a/apps/scandic-web/types/stores/booking-confirmation.ts +++ b/apps/scandic-web/types/stores/booking-confirmation.ts @@ -22,7 +22,7 @@ export interface Room { childrenAges?: number[] confirmationNumber: string currencyCode: CurrencyEnum - fromDate: Date + fromDate: string name: string packages: BookingConfirmation["booking"]["packages"] formattedRoomCost: string @@ -32,7 +32,7 @@ export interface Room { roomPoints: number roomPrice: number roomTypeCode: string | null - toDate: Date + toDate: string totalPrice: number totalPriceExVat: number vatAmount: number @@ -41,9 +41,9 @@ export interface Room { export interface InitialState { bookingCode: string | null - fromDate: Date + fromDate: string rooms: (Room | null)[] - toDate: Date + toDate: string currencyCode: CurrencyEnum roomCategories: RoomCategories vat: number diff --git a/apps/scandic-web/utils/dateFormatting.ts b/apps/scandic-web/utils/dateFormatting.ts index 3a7d48bfc..d1b8c3a9e 100644 --- a/apps/scandic-web/utils/dateFormatting.ts +++ b/apps/scandic-web/utils/dateFormatting.ts @@ -1,4 +1,4 @@ -import d from "dayjs" +import { dt } from "@/lib/dt" import type { Lang } from "@/constants/languages" @@ -16,6 +16,6 @@ export function getLocalizedMonthName(monthIndex: number, lang: Lang) { return monthName.charAt(0).toUpperCase() + monthName.slice(1) } -export function getNumberOfNights(startDate: Date, endDate: Date) { - return d(endDate).diff(startDate, "day") +export function getNumberOfNights(startDate: string, endDate: string) { + return dt(endDate).diff(startDate, "day") }