Skip to content

Commit

Permalink
fix: issue with timezone and android time picker (#4681)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelbr committed Aug 22, 2024
1 parent 234e0ae commit 3867e30
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export function TimeInputSectionItem(props: TimeInputSectionItemProps) {
<ButtonSectionItem
label={t(SectionTexts.timeInput.label)}
onPress={() => setShow(true)}
value={formatLocaleTime(time, language)}
value={formatLocaleTime(time, language, {
// Value is already adjusted to the timezone
ignoreTimeZone: true,
})}
containerStyle={{alignItems: 'flex-end'}}
{...innerprops}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {ThemeText} from '@atb/components/text';
import {StyleSheet} from '@atb/theme';
import {TripSearchTexts, useTranslation} from '@atb/translations';
import {daysBetween, formatToSimpleDate, isSameDay} from '@atb/utils/date';
import {parseISO} from 'date-fns';
import React from 'react';
import {ThemeText} from '@atb/components/text';

type OptionalNextDayLabelProps = {
departureTime: string;
Expand Down
16 changes: 12 additions & 4 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getMinutes,
getSeconds,
isPast,
isSameDay,
isSameDay as isSameDayInternal,
isSameYear,
isToday,
isWithinInterval,
Expand All @@ -27,6 +27,7 @@ import {
FormatOptionsWithTZ,
formatInTimeZone,
fromZonedTime,
toZonedTime,
} from 'date-fns-tz';
import {enGB as en, nb} from 'date-fns/locale';
import humanizeDuration from 'humanize-duration';
Expand Down Expand Up @@ -346,8 +347,6 @@ export function fullDateTime(isoDate: string | Date, language: Language) {
});
}

export {isSameDay};

export function formatToShortDate(date: Date | string, language: Language) {
return format(parseIfNeeded(date), 'dd. MMM', {
locale: languageToLocale(language),
Expand Down Expand Up @@ -442,7 +441,16 @@ export function formatToWeekday(
}

export function daysBetween(base: string | Date, target: string | Date) {
return differenceInCalendarDays(parseIfNeeded(target), parseIfNeeded(base));
return differenceInCalendarDays(
toZonedTime(parseIfNeeded(target), CET),
toZonedTime(parseIfNeeded(base), CET),
);
}
export function isSameDay(base: string | Date, target: string | Date) {
return isSameDayInternal(
toZonedTime(parseIfNeeded(target), CET),
toZonedTime(parseIfNeeded(base), CET),
);
}

export function isSeveralDays(items: string[]) {
Expand Down

0 comments on commit 3867e30

Please sign in to comment.