Merged in fix/add-years-to-get-days-until-text-util (pull request #3281)
fix: add years to getDaysUntilText + confirmation number in upcoming stay card * fix: add years to getDaysUntilText + confirmation number in upcoming stay card Approved-by: Erik Tiekstra Approved-by: Matilda Landström
This commit is contained in:
@@ -29,6 +29,7 @@ export default function CarouselCard({ stay }: CarouselCardProps) {
|
|||||||
const {
|
const {
|
||||||
checkinDate,
|
checkinDate,
|
||||||
checkoutDate,
|
checkoutDate,
|
||||||
|
confirmationNumber,
|
||||||
hotelInformation,
|
hotelInformation,
|
||||||
isWebAppOrigin,
|
isWebAppOrigin,
|
||||||
bookingUrl,
|
bookingUrl,
|
||||||
@@ -67,6 +68,20 @@ export default function CarouselCard({ stay }: CarouselCardProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
|
<div className={styles.infoRow}>
|
||||||
|
<Typography variant="Body/Paragraph/mdRegular">
|
||||||
|
<span className={styles.infoItem}>
|
||||||
|
<MaterialIcon icon="sticky_note_2" color="Icon/Default" />
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: "common.bookingNumber",
|
||||||
|
defaultMessage: "Booking number",
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="Body/Paragraph/mdRegular">
|
||||||
|
<span className={styles.dateRange}>{confirmationNumber}</span>
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
<div className={styles.infoRow}>
|
<div className={styles.infoRow}>
|
||||||
<Typography variant="Body/Paragraph/mdRegular">
|
<Typography variant="Body/Paragraph/mdRegular">
|
||||||
<span className={styles.infoItem}>
|
<span className={styles.infoItem}>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const mockIntl = {
|
|||||||
"nextStay.inXDays": `In {days} days`,
|
"nextStay.inXDays": `In {days} days`,
|
||||||
"nextStay.inXMonths":
|
"nextStay.inXMonths":
|
||||||
"In {months, plural, one {# month} other {# months}}",
|
"In {months, plural, one {# month} other {# months}}",
|
||||||
|
"nextStay.inXYears": "In {years, plural, one {# year} other {# years}}",
|
||||||
}
|
}
|
||||||
|
|
||||||
let message: string =
|
let message: string =
|
||||||
@@ -40,6 +41,18 @@ const mockIntl = {
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.includes("{years, plural")) {
|
||||||
|
const years = Number(values.years)
|
||||||
|
|
||||||
|
if (years === 1) {
|
||||||
|
message = "In 1 year"
|
||||||
|
} else {
|
||||||
|
message = `In ${years} years`
|
||||||
|
}
|
||||||
|
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
|
||||||
Object.entries(values).forEach(([key, value]) => {
|
Object.entries(values).forEach(([key, value]) => {
|
||||||
message = message.replace(`{${key}}`, String(value))
|
message = message.replace(`{${key}}`, String(value))
|
||||||
})
|
})
|
||||||
@@ -167,7 +180,40 @@ describe("getDaysUntilText", () => {
|
|||||||
const futureDate = dt().add(1, "year").format("YYYY-MM-DD")
|
const futureDate = dt().add(1, "year").format("YYYY-MM-DD")
|
||||||
const result = getDaysUntilText(futureDate, lang, mockIntl)
|
const result = getDaysUntilText(futureDate, lang, mockIntl)
|
||||||
|
|
||||||
expect(result).toBe("In 12 months")
|
expect(result).toBe("In 1 year")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("years until check-in (12+ months)", () => {
|
||||||
|
it("should return 'In 1 year' for 12 months", () => {
|
||||||
|
const futureDate = dt().add(12, "months").format("YYYY-MM-DD")
|
||||||
|
const result = getDaysUntilText(futureDate, lang, mockIntl)
|
||||||
|
|
||||||
|
expect(result).toBe("In 1 year")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return 'In 2 years' for dates 2 years away", () => {
|
||||||
|
const futureDate = dt().add(2, "years").format("YYYY-MM-DD")
|
||||||
|
const result = getDaysUntilText(futureDate, lang, mockIntl)
|
||||||
|
|
||||||
|
expect(result).toBe("In 2 years")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return 'In 5 years' for dates 5 years away", () => {
|
||||||
|
const futureDate = dt().add(5, "years").format("YYYY-MM-DD")
|
||||||
|
const result = getDaysUntilText(futureDate, lang, mockIntl)
|
||||||
|
|
||||||
|
expect(result).toBe("In 5 years")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle the boundary at 11 months vs 12 months", () => {
|
||||||
|
const date11Months = dt().add(11, "months").format("YYYY-MM-DD")
|
||||||
|
const date12Months = dt().add(12, "months").format("YYYY-MM-DD")
|
||||||
|
|
||||||
|
expect(getDaysUntilText(date11Months, lang, mockIntl)).toBe(
|
||||||
|
"In 11 months"
|
||||||
|
)
|
||||||
|
expect(getDaysUntilText(date12Months, lang, mockIntl)).toBe("In 1 year")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,28 @@ export function getDaysUntilText(
|
|||||||
|
|
||||||
// Use proper month calculation for dates beyond 30 days
|
// Use proper month calculation for dates beyond 30 days
|
||||||
const monthsUntil = checkInDateTime.diff(now, "months")
|
const monthsUntil = checkInDateTime.diff(now, "months")
|
||||||
|
|
||||||
|
if (monthsUntil <= 11) {
|
||||||
|
return intl.formatMessage(
|
||||||
|
{
|
||||||
|
id: "nextStay.inXMonths",
|
||||||
|
defaultMessage: "In {months, plural, one {# month} other { # months}}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
months: monthsUntil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 12+ months (show years)
|
||||||
|
const yearsUntil = checkInDateTime.diff(now, "years")
|
||||||
return intl.formatMessage(
|
return intl.formatMessage(
|
||||||
{
|
{
|
||||||
id: "nextStay.inXMonths",
|
id: "nextStay.inXYears",
|
||||||
defaultMessage: "In {months, plural, one {# month} other { # months}}",
|
defaultMessage: "In {years, plural, one {# year} other {# years}}",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
months: monthsUntil,
|
years: yearsUntil,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,7 +276,7 @@
|
|||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-display: block;
|
font-display: block;
|
||||||
src: url(/_static/shared/fonts/material-symbols/rounded-0ce1d4ea.woff2)
|
src: url(/_static/shared/fonts/material-symbols/rounded-b1df8938.woff2)
|
||||||
format('woff2');
|
format('woff2');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ const icons = [
|
|||||||
"sports_tennis",
|
"sports_tennis",
|
||||||
"stairs",
|
"stairs",
|
||||||
"star",
|
"star",
|
||||||
|
"sticky_note_2",
|
||||||
"straighten",
|
"straighten",
|
||||||
"styler",
|
"styler",
|
||||||
"support_agent",
|
"support_agent",
|
||||||
@@ -306,7 +307,7 @@ async function cleanFontDirs() {
|
|||||||
await writeFile(
|
await writeFile(
|
||||||
join(FONT_DIR, ".auto-generated"),
|
join(FONT_DIR, ".auto-generated"),
|
||||||
`Auto-generated, do not edit. Use scripts/material-symbols-update.mts to update.\nhash=${hash}\ncreated=${new Date().toISOString()}\n`,
|
`Auto-generated, do not edit. Use scripts/material-symbols-update.mts to update.\nhash=${hash}\ncreated=${new Date().toISOString()}\n`,
|
||||||
{ encoding: "utf-8" }
|
{ encoding: "utf-8" },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,11 +322,11 @@ async function updateFontCSS() {
|
|||||||
file,
|
file,
|
||||||
css.replace(
|
css.replace(
|
||||||
/url\(\/_static\/shared\/fonts\/material-symbols\/rounded[^)]+\)/,
|
/url\(\/_static\/shared\/fonts\/material-symbols\/rounded[^)]+\)/,
|
||||||
`url(/_static/shared/fonts/material-symbols/rounded-${hash}.woff2)`
|
`url(/_static/shared/fonts/material-symbols/rounded-${hash}.woff2)`,
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
encoding: "utf-8",
|
encoding: "utf-8",
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +346,7 @@ async function main() {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
`Unable to find the icon font src URL in CSS response from Google Fonts at ${fontUrl}`
|
`Unable to find the icon font src URL in CSS response from Google Fonts at ${fontUrl}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
Auto-generated, do not edit. Use scripts/material-symbols-update.mts to update.
|
Auto-generated, do not edit. Use scripts/material-symbols-update.mts to update.
|
||||||
hash=0ce1d4ea
|
hash=b1df8938
|
||||||
created=2025-12-03T15:14:42.683Z
|
created=2025-12-04T09:28:50.275Z
|
||||||
|
|||||||
Binary file not shown.
BIN
shared/fonts/material-symbols/rounded-b1df8938.woff2
Normal file
BIN
shared/fonts/material-symbols/rounded-b1df8938.woff2
Normal file
Binary file not shown.
Reference in New Issue
Block a user