Merged in fix/SW-3078-wrong-dates-time-zones (pull request #2388)
fix(SW-3078): change to string instead of Date in Zod schema * fix(SW-3078): change to string instead of Date in Zod schema Approved-by: Michael Zetterberg Approved-by: Linus Flood
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user