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"
|
import type { DateTime } from "ics"
|
||||||
|
|
||||||
export function generateDateTime(d: Date): DateTime {
|
export function generateDateTime(d: string): DateTime {
|
||||||
const _d = dt(d).utc()
|
const _d = dt(d).utc()
|
||||||
return [
|
return [
|
||||||
_d.year(),
|
_d.year(),
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import useLang from "@/hooks/useLang"
|
|||||||
import styles from "./newDates.module.css"
|
import styles from "./newDates.module.css"
|
||||||
|
|
||||||
interface NewDatesProps {
|
interface NewDatesProps {
|
||||||
checkInDate: Date
|
checkInDate: string
|
||||||
checkOutDate: Date
|
checkOutDate: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NewDates({ checkInDate, checkOutDate }: NewDatesProps) {
|
export default function NewDates({ checkInDate, checkOutDate }: NewDatesProps) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { dt } from "@/lib/dt"
|
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 hour = dt(time, "HH:mm").hour()
|
||||||
const minute = dt(time, "HH:mm").minute()
|
const minute = dt(time, "HH:mm").minute()
|
||||||
return dt(date).hour(hour).minute(minute).isBefore(dt(), "minutes")
|
return dt(date).hour(hour).minute(minute).isBefore(dt(), "minutes")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { BookingStatusEnum, ChildBedTypeEnum } from "@/constants/booking"
|
import { BookingStatusEnum, ChildBedTypeEnum } from "@/constants/booking"
|
||||||
|
import { dt } from "@/lib/dt"
|
||||||
|
|
||||||
import { calculateRefId } from "@/utils/refId"
|
import { calculateRefId } from "@/utils/refId"
|
||||||
import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator"
|
import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator"
|
||||||
@@ -208,8 +209,8 @@ export const bookingConfirmationSchema = z
|
|||||||
adults: z.number().int(),
|
adults: z.number().int(),
|
||||||
ancillary: ancillarySchema,
|
ancillary: ancillarySchema,
|
||||||
cancelationNumber: z.string().nullable().default(""),
|
cancelationNumber: z.string().nullable().default(""),
|
||||||
checkInDate: z.date({ coerce: true }),
|
checkInDate: z.string().refine((val) => dt(val).isValid()),
|
||||||
checkOutDate: z.date({ coerce: true }),
|
checkOutDate: z.string().refine((val) => dt(val).isValid()),
|
||||||
childBedPreferences: z.array(childBedPreferencesSchema).default([]),
|
childBedPreferences: z.array(childBedPreferencesSchema).default([]),
|
||||||
childrenAges: z.array(z.number().int()).default([]),
|
childrenAges: z.array(z.number().int()).default([]),
|
||||||
canChangeDate: z.boolean(),
|
canChangeDate: z.boolean(),
|
||||||
@@ -226,7 +227,7 @@ export const bookingConfirmationSchema = z
|
|||||||
.nullish(),
|
.nullish(),
|
||||||
computedReservationStatus: z.string().nullable().default(""),
|
computedReservationStatus: z.string().nullable().default(""),
|
||||||
confirmationNumber: nullableStringValidator,
|
confirmationNumber: nullableStringValidator,
|
||||||
createDateTime: z.date({ coerce: true }),
|
createDateTime: z.string().refine((val) => dt(val).isValid()),
|
||||||
currencyCode: z.nativeEnum(CurrencyEnum),
|
currencyCode: z.nativeEnum(CurrencyEnum),
|
||||||
guest: guestSchema,
|
guest: guestSchema,
|
||||||
linkedReservations: nullableArrayObjectValidator(
|
linkedReservations: nullableArrayObjectValidator(
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ export interface BookingConfirmationProviderProps
|
|||||||
extends React.PropsWithChildren {
|
extends React.PropsWithChildren {
|
||||||
bookingCode: string | null
|
bookingCode: string | null
|
||||||
currencyCode: CurrencyEnum
|
currencyCode: CurrencyEnum
|
||||||
fromDate: Date
|
fromDate: string
|
||||||
roomCategories: RoomCategories
|
roomCategories: RoomCategories
|
||||||
rooms: (Room | null)[]
|
rooms: (Room | null)[]
|
||||||
toDate: Date
|
toDate: string
|
||||||
vat: number
|
vat: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export interface Room {
|
|||||||
childrenAges?: number[]
|
childrenAges?: number[]
|
||||||
confirmationNumber: string
|
confirmationNumber: string
|
||||||
currencyCode: CurrencyEnum
|
currencyCode: CurrencyEnum
|
||||||
fromDate: Date
|
fromDate: string
|
||||||
name: string
|
name: string
|
||||||
packages: BookingConfirmation["booking"]["packages"]
|
packages: BookingConfirmation["booking"]["packages"]
|
||||||
formattedRoomCost: string
|
formattedRoomCost: string
|
||||||
@@ -32,7 +32,7 @@ export interface Room {
|
|||||||
roomPoints: number
|
roomPoints: number
|
||||||
roomPrice: number
|
roomPrice: number
|
||||||
roomTypeCode: string | null
|
roomTypeCode: string | null
|
||||||
toDate: Date
|
toDate: string
|
||||||
totalPrice: number
|
totalPrice: number
|
||||||
totalPriceExVat: number
|
totalPriceExVat: number
|
||||||
vatAmount: number
|
vatAmount: number
|
||||||
@@ -41,9 +41,9 @@ export interface Room {
|
|||||||
|
|
||||||
export interface InitialState {
|
export interface InitialState {
|
||||||
bookingCode: string | null
|
bookingCode: string | null
|
||||||
fromDate: Date
|
fromDate: string
|
||||||
rooms: (Room | null)[]
|
rooms: (Room | null)[]
|
||||||
toDate: Date
|
toDate: string
|
||||||
currencyCode: CurrencyEnum
|
currencyCode: CurrencyEnum
|
||||||
roomCategories: RoomCategories
|
roomCategories: RoomCategories
|
||||||
vat: number
|
vat: number
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import d from "dayjs"
|
import { dt } from "@/lib/dt"
|
||||||
|
|
||||||
import type { Lang } from "@/constants/languages"
|
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)
|
return monthName.charAt(0).toUpperCase() + monthName.slice(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNumberOfNights(startDate: Date, endDate: Date) {
|
export function getNumberOfNights(startDate: string, endDate: string) {
|
||||||
return d(endDate).diff(startDate, "day")
|
return dt(endDate).diff(startDate, "day")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user