Skip to content

Fixed trip cancellation text #61205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,19 @@ function getFormattedTransportDateAndHour(date: Date): {date: string; hour: stri
};
}

/**
* Returns a formatted cancellation date.
* Dates are formatted as follows:
* 1. When the date refers to the current year: Wednesday, Mar 17 8:00 AM
* 2. When the date refers not to the current year: Wednesday, Mar 17, 2023 8:00 AM
*/
function getFormattedCancellationDate(date: Date): string {
if (isThisYear(date)) {
return format(date, 'EEEE, MMM d h:mm a');
}
return format(date, 'EEEE, MMM d, yyyy h:mm a');
}

/**
* Returns a formatted layover duration in format "2h 30m".
*/
Expand Down Expand Up @@ -998,6 +1011,7 @@ const DateUtils = {
getFormattedReservationRangeDate,
getFormattedTransportDate,
getFormattedTransportDateAndHour,
getFormattedCancellationDate,
doesDateBelongToAPastYear,
isCardExpired,
getDifferenceInDaysFromNow,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Travel/CarTripDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function CarTripDetails({reservation, personalDetails}: CarTripDetailsProps) {

let cancellationText = reservation.cancellationPolicy;
if (reservation.cancellationDeadline) {
cancellationText = `${translate('travel.carDetails.cancellationUntil')} ${DateUtils.getFormattedTransportDateAndHour(new Date(reservation.cancellationDeadline)).date}`;
cancellationText = `${translate('travel.carDetails.cancellationUntil')} ${DateUtils.getFormattedCancellationDate(new Date(reservation.cancellationDeadline))}`;
}

if (reservation.cancellationPolicy === null && reservation.cancellationDeadline === null) {
Expand Down Expand Up @@ -71,6 +71,7 @@ function CarTripDetails({reservation, personalDetails}: CarTripDetailsProps) {
description={translate('travel.carDetails.cancellation')}
title={cancellationText}
interactive={false}
numberOfLinesTitle={2}
/>
)}
{!!reservation.reservationID && (
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Travel/HotelTripDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function HotelTripDetails({reservation, personalDetails}: HotelTripDetailsProps)
const checkInDate = DateUtils.getFormattedTransportDateAndHour(new Date(reservation.start.date));
const checkOutDate = DateUtils.getFormattedTransportDateAndHour(new Date(reservation.end.date));
const cancellationText = reservation.cancellationDeadline
? `${translate('travel.hotelDetails.cancellationUntil')} ${DateUtils.getFormattedTransportDateAndHour(new Date(reservation.cancellationDeadline)).date}`
? `${translate('travel.hotelDetails.cancellationUntil')} ${DateUtils.getFormattedCancellationDate(new Date(reservation.cancellationDeadline))}`
: cancellationMapping[reservation.cancellationPolicy ?? CONST.CANCELLATION_POLICY.UNKNOWN];

const displayName = personalDetails?.displayName ?? reservation.travelerPersonalInfo?.name;
Expand Down Expand Up @@ -70,6 +70,7 @@ function HotelTripDetails({reservation, personalDetails}: HotelTripDetailsProps)
description={translate('travel.hotelDetails.cancellation')}
title={cancellationText}
interactive={false}
numberOfLinesTitle={2}
/>
)}
{!!reservation.confirmations?.at(0)?.value && (
Expand Down