Skip to content

Commit

Permalink
fix: showing the day when a departure happens on a new date (#1803)
Browse files Browse the repository at this point in the history
* fixed showing the day when a departure happens on a new date

* updated to follow correct norwegian abbreviation for weekdays
  • Loading branch information
brorhb authored Nov 26, 2021
1 parent 44ca3a4 commit 3819ddc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/departure-list/section-items/line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import {
import {
formatToClock,
formatToClockOrRelativeMinutes,
formatToShortSimpleDate,
formatToWeekday,
isInThePast,
isRelativeButNotNow,
isWithin24Hours,
isWithinSameDate,
} from '@atb/utils/date';
import insets from '@atb/utils/insets';
import {TFunc} from '@leile/lobo-t';
Expand Down Expand Up @@ -242,7 +242,6 @@ function DepartureTimeItem({
if (!isValidDeparture(departure)) {
return null;
}

return (
<Button
key={departure.serviceJourneyId}
Expand Down Expand Up @@ -285,14 +284,10 @@ const addDatePrefixIfNecessary = (
departureDate: string,
searchDate: string,
) => {
if (isWithin24Hours(searchDate, departureDate)) {
if (isWithinSameDate(searchDate, departureDate)) {
return timeText;
} else {
return (
formatToShortSimpleDate(departureDate, Language.Norwegian) +
' ' +
timeText
);
return `${formatToWeekday(departureDate, Language.Norwegian)}. ${timeText}`;
}
};

Expand Down
15 changes: 15 additions & 0 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ export const isWithin24Hours = (
});
};

export const isWithinSameDate = (
dateLeft: Date | string,
dateRight: Date | string,
) => {
const leftParsed = parseIfNeeded(dateLeft);
const rightParsed = parseIfNeeded(dateRight);
return isSameDay(leftParsed, rightParsed);
};

export function formatToShortSimpleDate(
date: Date | string,
language: Language,
Expand All @@ -187,6 +196,12 @@ export function formatToShortSimpleDate(
});
}

export function formatToWeekday(date: Date | string, language: Language) {
return format(parseIfNeeded(date), 'EEEEEE', {
locale: languageToLocale(language),
});
}

export function daysBetween(base: Date, target: Date) {
return differenceInCalendarDays(target, base);
}
Expand Down

0 comments on commit 3819ddc

Please sign in to comment.