Files
web/apps/scandic-web/components/Blocks/DynamicContent/Stays/NextStay/utils.ts
Chuma Mcphoy (We Ahead) 94f6af563d Merged in feat/LOY-421-Next-Stay (pull request #3026)
Feat(LOY-421): Next Stay

* feat(LOY-421): Next stay WIP

* fix(LOY-421): clean upp css and jsx

* chore(LOY-421): css cleanup

* fix(LOY-421): fix test

* only show button if isWebAppOrigin is true

* chore(LOY-421): update section header component

* chore(LOY-421): remove redundant test case


Approved-by: Matilda Landström
2025-11-05 09:09:57 +00:00

66 lines
1.5 KiB
TypeScript

import { dt } from "@scandic-hotels/common/dt"
import type { Lang } from "@scandic-hotels/common/constants/language"
import type { IntlShape } from "react-intl"
export function getDaysUntilText(
checkinDate: string,
lang: Lang,
intl: IntlShape
): string {
const checkInDateTime = dt(checkinDate).locale(lang).startOf("day")
const now = dt().locale(lang).startOf("day")
const daysUntil = checkInDateTime.diff(now, "days")
// Handle past dates edge case.
if (daysUntil < 0) {
return intl.formatMessage(
{
id: "nextStay.past",
defaultMessage: "{date} ",
},
{
date: dt(checkinDate).locale(lang).format("D MMM YYYY"),
}
)
}
if (daysUntil === 0) {
return intl.formatMessage({
id: "nextStay.today",
defaultMessage: "Today",
})
}
if (daysUntil === 1) {
return intl.formatMessage({
id: "nextStay.tomorrow",
defaultMessage: "Tomorrow",
})
}
if (daysUntil > 1 && daysUntil <= 30) {
return intl.formatMessage(
{
id: "nextStay.inXDays",
defaultMessage: "In {days} days",
},
{
days: daysUntil,
}
)
}
// Use proper month calculation for dates beyond 30 days
const monthsUntil = checkInDateTime.diff(now, "months")
return intl.formatMessage(
{
id: "nextStay.inXMonths",
defaultMessage: "In {months} month{months, plural, =1 {} other {s}}",
},
{
months: monthsUntil,
}
)
}