Skip to content
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
2 changes: 1 addition & 1 deletion src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import DisplayNames from '@components/DisplayNames';
import Hoverable from '@components/Hoverable';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';

Check warning on line 7 in src/components/LHNOptionsList/OptionRowLHN.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 7 in src/components/LHNOptionsList/OptionRowLHN.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {useSession} from '@components/OnyxListItemProvider';
import PressableWithSecondaryInteraction from '@components/PressableWithSecondaryInteraction';
Expand Down Expand Up @@ -163,7 +163,7 @@
const statusText = optionItem.status?.text ?? '';
const statusClearAfterDate = optionItem.status?.clearAfter ?? '';
const currentSelectedTimezone = currentUserPersonalDetails?.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected;
const formattedDate = DateUtils.getStatusUntilDate(statusClearAfterDate, optionItem?.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected, currentSelectedTimezone);
const formattedDate = DateUtils.getStatusUntilDate(translate, statusClearAfterDate, optionItem?.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected, currentSelectedTimezone);
const statusContent = formattedDate ? `${statusText ? `${statusText} ` : ''}(${formattedDate})` : statusText;
const isStatusVisible = !!emojiCode && isOneOnOneChat(!isEmptyObject(report) ? report : undefined);

Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/TripDetailsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import Navigation from '@libs/Navigation/Navigation';
import StringUtils from '@libs/StringUtils';
import variables from '@styles/variables';
import * as Expensicons from '@src/components/Icon/Expensicons';

Check warning on line 23 in src/components/ReportActionItem/TripDetailsView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@src/components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import CONST from '@src/CONST';
import type {ReservationData} from '@src/libs/TripReservationUtils';
import {formatAirportInfo, getPNRReservationDataFromTripReport, getTripReservationCode, getTripReservationIcon} from '@src/libs/TripReservationUtils';
Expand Down Expand Up @@ -51,10 +51,10 @@
const getFormattedDate = () => {
switch (reservation.type) {
case CONST.RESERVATION_TYPE.FLIGHT:
return DateUtils.getFormattedTransportDate(new Date(reservation.start.date));
return DateUtils.getFormattedTransportDate(translate, new Date(reservation.start.date));
case CONST.RESERVATION_TYPE.HOTEL:
case CONST.RESERVATION_TYPE.CAR:
return DateUtils.getFormattedReservationRangeDate(new Date(reservation.start.date), new Date(reservation.end.date));
return DateUtils.getFormattedReservationRangeDate(translate, new Date(reservation.start.date), new Date(reservation.end.date));
default:
return DateUtils.formatToLongDateWithWeekday(new Date(reservation.start.date));
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/TripRoomPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function TripRoomPreview({
const reservationsData: ReservationData[] = getReservationsFromTripReport(chatReport, tripTransactions);
const dateInfo =
chatReport?.tripData?.startDate && chatReport?.tripData?.endDate
? DateUtils.getFormattedDateRange(new Date(chatReport.tripData.startDate), new Date(chatReport.tripData.endDate))
? DateUtils.getFormattedDateRange(translate, new Date(chatReport.tripData.startDate), new Date(chatReport.tripData.endDate))
: '';
const reportCurrency = iouReport?.currency ?? chatReport?.currency;

Expand Down
69 changes: 27 additions & 42 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ import {
import {formatInTimeZone, fromZonedTime, toDate, toZonedTime, format as tzFormat} from 'date-fns-tz';
import throttle from 'lodash/throttle';
import type {ValueOf} from 'type-fest';
import type {LocaleContextProps} from '@components/LocaleContextProvider';
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import {timezoneBackwardToNewMap, timezoneNewToBackwardMap} from '@src/TIMEZONES';
import type Locale from '@src/types/onyx/Locale';
import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {setCurrentDate} from './actions/CurrentDate';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translate, translateLocal} from './Localize';
import {translate as translateLocalize} from './Localize';
import Log from './Log';
import memoize from './memoize';

Expand Down Expand Up @@ -167,10 +166,10 @@ const fallbackToSupportedTimezone = memoize((timezoneInput: SelectedTimezone): S
function datetimeToCalendarTime(locale: Locale | undefined, datetime: string, currentSelectedTimezone: SelectedTimezone, includeTimeZone = false, isLowercase = false): string {
const date = getLocalDateFromDatetime(locale, fallbackToSupportedTimezone(currentSelectedTimezone), datetime);
const tz = includeTimeZone ? ' [UTC]Z' : '';
let todayAt = translate(locale, 'common.todayAt');
let tomorrowAt = translate(locale, 'common.tomorrowAt');
let yesterdayAt = translate(locale, 'common.yesterdayAt');
const at = translate(locale, 'common.conjunctionAt');
let todayAt = translateLocalize(locale, 'common.todayAt');
let tomorrowAt = translateLocalize(locale, 'common.tomorrowAt');
let yesterdayAt = translateLocalize(locale, 'common.yesterdayAt');
const at = translateLocalize(locale, 'common.conjunctionAt');
const weekStartsOn = getWeekStartsOn();

const startOfCurrentWeek = startOfWeek(new Date(), {weekStartsOn});
Expand Down Expand Up @@ -466,15 +465,13 @@ function getDateFromStatusType(type: CustomStatusTypes): string {
* param {string} data - either a value from CONST.CUSTOM_STATUS_TYPES or a dateTime string in the format YYYY-MM-DD HH:mm
* returns {string} example: 2023-05-16 11:10 PM or 'Today'
*/
function getLocalizedTimePeriodDescription(data: string): string {
function getLocalizedTimePeriodDescription(translate: LocalizedTranslate, data: string): string {
switch (data) {
case getEndOfToday():
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('statusPage.timePeriods.afterToday');
return translate('statusPage.timePeriods.afterToday');
case CONST.CUSTOM_STATUS_TYPES.NEVER:
case '':
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('statusPage.timePeriods.never');
return translate('statusPage.timePeriods.never');
default:
return formatDateTimeTo12Hour(data);
}
Expand All @@ -487,7 +484,7 @@ function getLocalizedTimePeriodDescription(data: string): string {
* param {SelectedTimezone} currentSelectedTimezone - Current user's timezone to display the result in.
* returns {string} - A localized string such as 'Until 05:34 PM', 'Until tomorrow', or 'Until Jul 01 05:34 PM'.
*/
function getStatusUntilDate(inputDate: string, inputDateTimeZone: SelectedTimezone, currentSelectedTimezone: SelectedTimezone): string {
function getStatusUntilDate(translate: LocalizedTranslate, inputDate: string, inputDateTimeZone: SelectedTimezone, currentSelectedTimezone: SelectedTimezone): string {
if (!inputDate) {
return '';
}
Expand All @@ -499,25 +496,21 @@ function getStatusUntilDate(inputDate: string, inputDateTimeZone: SelectedTimezo

// If the date is adjusted to the following day
if (isSameSecond(input, endOfToday)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('statusPage.untilTomorrow');
return translate('statusPage.untilTomorrow');
}

// If it's a time on the same date
if (isSameDay(input, now)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('statusPage.untilTime', {time: format(input, CONST.DATE.LOCAL_TIME_FORMAT)});
return translate('statusPage.untilTime', {time: format(input, CONST.DATE.LOCAL_TIME_FORMAT)});
}

// If it's further in the future than tomorrow but within the same year
if (isAfter(input, now) && isSameYear(input, now)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('statusPage.untilTime', {time: format(input, `${CONST.DATE.SHORT_DATE_FORMAT} ${CONST.DATE.LOCAL_TIME_FORMAT}`)});
return translate('statusPage.untilTime', {time: format(input, `${CONST.DATE.SHORT_DATE_FORMAT} ${CONST.DATE.LOCAL_TIME_FORMAT}`)});
}

// If it's in another year
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('statusPage.untilTime', {time: format(input, `${CONST.DATE.FNS_FORMAT_STRING} ${CONST.DATE.LOCAL_TIME_FORMAT}`)});
return translate('statusPage.untilTime', {time: format(input, `${CONST.DATE.FNS_FORMAT_STRING} ${CONST.DATE.LOCAL_TIME_FORMAT}`)});
}

/**
Expand Down Expand Up @@ -639,14 +632,13 @@ const isValidStartEndTimeRange = ({startTime, endTime}: {startTime: string; endT
* param {Date} referenceDate - The date to compare against.
* returns {string} - Returns an error key if validation fails, otherwise an empty string.
*/
const getDayValidationErrorKey = (inputDate: Date): string => {
const getDayValidationErrorKey = (translate: LocalizedTranslate, inputDate: Date): string => {
if (!inputDate) {
return '';
}

if (isAfter(startOfDay(new Date()), startOfDay(inputDate))) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('common.error.invalidDateShouldBeFuture');
return translate('common.error.invalidDateShouldBeFuture');
}
return '';
};
Expand All @@ -666,11 +658,10 @@ const isFutureDay = (inputDate: Date): boolean => {
* param {Date} referenceTime - The time to compare against.
* returns {string} - Returns an error key if validation fails, otherwise an empty string.
*/
const getTimeValidationErrorKey = (inputTime: Date): string => {
const getTimeValidationErrorKey = (translate: LocalizedTranslate, inputTime: Date): string => {
const timeNowPlusOneMinute = addMinutes(new Date(), 1);
if (isBefore(inputTime, timeNowPlusOneMinute)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return translateLocal('common.error.invalidTimeShouldBeFuture');
return translate('common.error.invalidTimeShouldBeFuture');
}
return '';
};
Expand Down Expand Up @@ -735,7 +726,7 @@ function getLastBusinessDayOfMonth(inputDate: Date): number {
* 3. When both dates refer to the same year: Feb 28 to Mar 1
* 4. When the dates are from different years: Dec 28, 2023 to Jan 5, 2024
*/
function getFormattedDateRange(date1: Date, date2: Date): string {
function getFormattedDateRange(translate: LocalizedTranslate, date1: Date, date2: Date): string {
if (isSameDay(date1, date2)) {
// Dates are from the same day
return format(date1, 'MMM d');
Expand All @@ -746,12 +737,10 @@ function getFormattedDateRange(date1: Date, date2: Date): string {
}
if (isSameYear(date1, date2)) {
// Dates are in the same year, differ by months
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${format(date1, 'MMM d')} ${translateLocal('common.to').toLowerCase()} ${format(date2, 'MMM d')}`;
return `${format(date1, 'MMM d')} ${translate('common.to').toLowerCase()} ${format(date2, 'MMM d')}`;
}
// Dates differ by years, months, days
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${format(date1, 'MMM d, yyyy')} ${translateLocal('common.to').toLowerCase()} ${format(date2, 'MMM d, yyyy')}`;
return `${format(date1, 'MMM d, yyyy')} ${translate('common.to').toLowerCase()} ${format(date2, 'MMM d, yyyy')}`;
}

/**
Expand All @@ -762,7 +751,7 @@ function getFormattedDateRange(date1: Date, date2: Date): string {
* 3. When both dates refer to the current year: Sunday, Mar 17 to Wednesday, Mar 20
* 4. When the dates are from different years or from a year which is not current: Wednesday, Mar 17, 2023 to Saturday, Jan 20, 2024
*/
function getFormattedReservationRangeDate(date1: Date, date2: Date): string {
function getFormattedReservationRangeDate(translate: LocalizedTranslate, date1: Date, date2: Date): string {
if (isSameDay(date1, date2) && isThisYear(date1)) {
// Dates are from the same day
return format(date1, 'EEEE, MMM d');
Expand All @@ -773,12 +762,10 @@ function getFormattedReservationRangeDate(date1: Date, date2: Date): string {
}
if (isSameYear(date1, date2) && isThisYear(date1)) {
// Dates are in the current year, differ by months
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${format(date1, 'EEEE, MMM d')} ${translateLocal('common.conjunctionTo')} ${format(date2, 'EEEE, MMM d')}`;
return `${format(date1, 'EEEE, MMM d')} ${translate('common.conjunctionTo')} ${format(date2, 'EEEE, MMM d')}`;
}
// Dates differ by years, months, days or only by months but the year is not current
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${format(date1, 'EEEE, MMM d, yyyy')} ${translateLocal('common.conjunctionTo')} ${format(date2, 'EEEE, MMM d, yyyy')}`;
return `${format(date1, 'EEEE, MMM d, yyyy')} ${translate('common.conjunctionTo')} ${format(date2, 'EEEE, MMM d, yyyy')}`;
}

/**
Expand All @@ -787,13 +774,11 @@ function getFormattedReservationRangeDate(date1: Date, date2: Date): string {
* 1. When the date refers to the current year: Departs on Sunday, Mar 17 at 8:00.
* 2. When the date refers not to the current year: Departs on Wednesday, Mar 17, 2023 at 8:00.
*/
function getFormattedTransportDate(date: Date): string {
function getFormattedTransportDate(translate: LocalizedTranslate, date: Date): string {
if (isThisYear(date)) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${translateLocal('travel.departs')} ${format(date, 'EEEE, MMM d')} ${translateLocal('common.conjunctionAt')} ${format(date, 'hh:mm a')}`;
return `${translate('travel.departs')} ${format(date, 'EEEE, MMM d')} ${translate('common.conjunctionAt')} ${format(date, 'hh:mm a')}`;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return `${translateLocal('travel.departs')} ${format(date, 'EEEE, MMM d, yyyy')} ${translateLocal('common.conjunctionAt')} ${format(date, 'hh:mm a')}`;
return `${translate('travel.departs')} ${format(date, 'EEEE, MMM d, yyyy')} ${translate('common.conjunctionAt')} ${format(date, 'hh:mm a')}`;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import isEmpty from 'lodash/isEmpty';
import isObject from 'lodash/isObject';
import type {OnyxCollection} from 'react-native-onyx';
import type {FormInputErrors, FormOnyxKeys, FormOnyxValues, FormValue} from '@components/Form/types';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import CONST from '@src/CONST';
import type {Country} from '@src/CONST';
import type {OnyxFormKey} from '@src/ONYXKEYS';
Expand Down Expand Up @@ -469,7 +470,7 @@ type DateTimeValidationErrorKeys = {
* data - A date and time string in 'YYYY-MM-DD HH:mm:ss.sssZ' format
* returns an object containing the error messages for the date and time
*/
const validateDateTimeIsAtLeastOneMinuteInFuture = (data: string): DateTimeValidationErrorKeys => {
const validateDateTimeIsAtLeastOneMinuteInFuture = (translate: LocalizedTranslate, data: string): DateTimeValidationErrorKeys => {
if (!data) {
return {
dateValidationErrorKey: '',
Expand All @@ -478,8 +479,8 @@ const validateDateTimeIsAtLeastOneMinuteInFuture = (data: string): DateTimeValid
}
const parsedInputData = parseISO(data);

const dateValidationErrorKey = DateUtils.getDayValidationErrorKey(parsedInputData);
const timeValidationErrorKey = DateUtils.getTimeValidationErrorKey(parsedInputData);
const dateValidationErrorKey = DateUtils.getDayValidationErrorKey(translate, parsedInputData);
const timeValidationErrorKey = DateUtils.getTimeValidationErrorKey(translate, parsedInputData);
return {
dateValidationErrorKey,
timeValidationErrorKey,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function ReportActionItemSingle({

const currentSelectedTimezone = currentUserPersonalDetails?.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected;
const hasEmojiStatus = !details.shouldDisplayAllActors && details.status?.emojiCode;
const formattedDate = DateUtils.getStatusUntilDate(details.status?.clearAfter ?? '', details.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected, currentSelectedTimezone);
const formattedDate = DateUtils.getStatusUntilDate(translate, details.status?.clearAfter ?? '', details.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected, currentSelectedTimezone);
const statusText = details.status?.text ?? '';
const statusTooltipText = formattedDate ? `${statusText ? `${statusText} ` : ''}(${formattedDate})` : statusText;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import type {ValueOf} from 'type-fest';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
Expand Down Expand Up @@ -42,11 +43,11 @@ function getSelectedStatusType(data: string): CustomStatusTypes {
}
}

const useValidateCustomDate = (data: string) => {
const useValidateCustomDate = (translate: LocalizedTranslate, data: string) => {
const [customDateError, setCustomDateError] = useState('');
const [customTimeError, setCustomTimeError] = useState('');
const validate = () => {
const {dateValidationErrorKey, timeValidationErrorKey} = validateDateTimeIsAtLeastOneMinuteInFuture(data);
const {dateValidationErrorKey, timeValidationErrorKey} = validateDateTimeIsAtLeastOneMinuteInFuture(translate, data);

setCustomDateError(dateValidationErrorKey);
setCustomTimeError(timeValidationErrorKey);
Expand Down Expand Up @@ -91,7 +92,7 @@ function StatusClearAfterPage() {
[draftPeriod, translate],
);

const {customDateError, customTimeError} = useValidateCustomDate(draftClearAfter);
const {customDateError, customTimeError} = useValidateCustomDate(translate, draftClearAfter);

const {redBrickDateIndicator, redBrickTimeIndicator} = useMemo(
() => ({
Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings/Profile/CustomStatus/StatusPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import InputWrapper from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues, FormRef} from '@components/Form/types';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';

Check warning on line 9 in src/pages/settings/Profile/CustomStatus/StatusPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used by a pattern. Direct imports from Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details

Check warning on line 9 in src/pages/settings/Profile/CustomStatus/StatusPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'@components/Icon/Expensicons' import is restricted from being used. Direct imports from @components/Icon/Expensicons are deprecated. Please use lazy loading hooks instead. Use `useMemoizedLazyExpensifyIcons` from @hooks/useLazyAsset. See docs/LAZY_ICONS_AND_ILLUSTRATIONS.md for details
import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand Down Expand Up @@ -75,8 +75,8 @@
const customClearAfter = useMemo(() => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const dataToShow = draftClearAfter || currentUserClearAfter;
return DateUtils.getLocalizedTimePeriodDescription(dataToShow);
}, [draftClearAfter, currentUserClearAfter]);
return DateUtils.getLocalizedTimePeriodDescription(translate, dataToShow);
}, [draftClearAfter, currentUserClearAfter, translate]);

const isValidClearAfterDate = useCallback(() => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down
Loading
Loading