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
18 changes: 1 addition & 17 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ const CONST = {
SHORT_DATE_FORMAT: 'MM-dd',
MONTH_DAY_YEAR_ABBR_FORMAT: 'MMM d, yyyy',
MONTH_DAY_YEAR_FORMAT: 'MMMM d, yyyy',
MONTH_DAY_WEEKDAY_ABBR_FORMAT: 'EEEE, MMM d',
MONTH_DAY_WEEKDAY_YEAR_ABBR_FORMAT: 'EEEE, MMM d, yyyy',
FNS_TIMEZONE_FORMAT_STRING: "yyyy-MM-dd'T'HH:mm:ssXXX",
FNS_DB_FORMAT_STRING: 'yyyy-MM-dd HH:mm:ss.SSS',
LONG_DATE_FORMAT_WITH_WEEKDAY: 'eeee, MMMM d, yyyy',
Expand Down Expand Up @@ -8070,20 +8068,6 @@ const FRAUD_PROTECTION_EVENT = {
NEW_EMAILS_INVITED: 'NewEmailsInvited',
};

const DATE_TIME_FORMAT_OPTIONS: Record<string, Intl.DateTimeFormatOptions> = {
[CONST.DATE.FNS_FORMAT_STRING]: {year: 'numeric', month: '2-digit', day: '2-digit'},
[CONST.DATE.LOCAL_TIME_FORMAT]: {timeStyle: 'short'},
[CONST.DATE.MONTH_FORMAT]: {month: 'long'},
[CONST.DATE.WEEKDAY_TIME_FORMAT]: {weekday: 'long'},
[CONST.DATE.MONTH_DAY_WEEKDAY_ABBR_FORMAT]: {weekday: 'long', month: 'short', day: 'numeric'},
[CONST.DATE.MONTH_DAY_WEEKDAY_YEAR_ABBR_FORMAT]: {weekday: 'long', month: 'short', day: 'numeric', year: 'numeric'},
[CONST.DATE.MONTH_DAY_YEAR_FORMAT]: {dateStyle: 'long'},
[CONST.DATE.MONTH_DAY_YEAR_ABBR_FORMAT]: {month: 'short', day: 'numeric', year: 'numeric'},
[CONST.DATE.LONG_DATE_FORMAT_WITH_WEEKDAY]: {dateStyle: 'full'},
FNS_DATE_WITH_LOCAL_TIME_FORMAT: {year: 'numeric', month: '2-digit', day: '2-digit', hour: 'numeric', minute: '2-digit'},
SHORT_DATE_WITH_LOCAL_TIME_FORMAT: {month: '2-digit', day: '2-digit', hour: 'numeric', minute: '2-digit'},
};

const COUNTRIES_US_BANK_FLOW: string[] = [CONST.COUNTRY.US, CONST.COUNTRY.PR, CONST.COUNTRY.GU, CONST.COUNTRY.VI];

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand All @@ -8099,6 +8083,6 @@ type CancellationType = ValueOf<typeof CONST.CANCELLATION_TYPE>;

export type {Country, IOUAction, IOUType, IOURequestType, SubscriptionType, FeedbackSurveyOptionID, CancellationType, OnboardingInvite, OnboardingAccounting, IOUActionParams};

export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS, TASK_TO_FEATURE, FRAUD_PROTECTION_EVENT, COUNTRIES_US_BANK_FLOW, DATE_TIME_FORMAT_OPTIONS};
export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS, TASK_TO_FEATURE, FRAUD_PROTECTION_EVENT, COUNTRIES_US_BANK_FLOW};

export default CONST;
4 changes: 2 additions & 2 deletions src/components/AutoUpdateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type AutoUpdateTimeProps = {
};

function AutoUpdateTime({timezone}: AutoUpdateTimeProps) {
const {translate, getLocalDateFromDatetime, preferredLocale} = useLocalize();
const {translate, getLocalDateFromDatetime} = useLocalize();
const styles = useThemeStyles();
/** @returns Returns the locale Date object */
const getCurrentUserLocalTime = useCallback(() => getLocalDateFromDatetime(undefined, timezone.selected), [getLocalDateFromDatetime, timezone.selected]);
Expand Down Expand Up @@ -50,7 +50,7 @@ function AutoUpdateTime({timezone}: AutoUpdateTimeProps) {
<View style={[styles.w100, styles.detailsPageSectionContainer]}>
<MenuItemWithTopDescription
style={[styles.ph0]}
title={`${DateUtils.formatToLocalTime(currentUserLocalTime, preferredLocale)} ${timezoneName}`}
title={`${DateUtils.formatToLocalTime(currentUserLocalTime)} ${timezoneName}`}
description={translate('detailsPage.localTime')}
interactive={false}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {addDays, format, getDay, getDaysInMonth, startOfMonth} from 'date-fns';
import DateUtils from '@libs/DateUtils';
import CONST from '@src/CONST';
import type Locale from '@src/types/onyx/Locale';

/**
* Generates a matrix representation of a month's calendar given the year and month.
Expand All @@ -10,7 +8,7 @@ import type Locale from '@src/types/onyx/Locale';
* @param month - The month (0-indexed) for which to generate the month matrix.
* @returns A 2D array of the month's calendar days, with null values representing days outside the current month.
*/
export default function generateMonthMatrix(year: number, month: number, locale: Locale = CONST.LOCALES.DEFAULT) {
export default function generateMonthMatrix(year: number, month: number) {
if (year < 0) {
throw new Error('Year cannot be less than 0');
}
Expand All @@ -22,7 +20,7 @@ export default function generateMonthMatrix(year: number, month: number, locale:
}

// Get the week day for the end of week
const weekEndsOn = DateUtils.getWeekEndsOn(locale);
const weekEndsOn = DateUtils.getWeekEndsOn();

// Get the number of days in the month and the first day of the month
const firstDayOfMonth = startOfMonth(new Date(year, month, 1));
Expand Down
12 changes: 5 additions & 7 deletions src/components/DatePicker/CalendarPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ function CalendarPicker({
const {isSmallScreenWidth} = useResponsiveLayout();
const styles = useThemeStyles();
const themeStyles = useThemeStyles();
const {translate, preferredLocale} = useLocalize();
const {translate} = useLocalize();
const pressableRef = useRef<View>(null);
const [currentDateView, setCurrentDateView] = useState(() => getInitialCurrentDateView(value, minDate, maxDate));
const [isYearPickerVisible, setIsYearPickerVisible] = useState(false);
const isFirstRender = useRef(true);

const currentMonthView = currentDateView.getMonth();
const currentYearView = currentDateView.getFullYear();
const calendarDaysMatrix = generateMonthMatrix(currentYearView, currentMonthView, preferredLocale);
const calendarDaysMatrix = generateMonthMatrix(currentYearView, currentMonthView);
const initialHeight = (calendarDaysMatrix?.length || CONST.MAX_CALENDAR_PICKER_ROWS) * CONST.CALENDAR_PICKER_DAY_HEIGHT;
const heightValue = useSharedValue(initialHeight);

Expand Down Expand Up @@ -105,9 +105,7 @@ function CalendarPicker({
*/
const onDayPressed = (day: number) => {
setCurrentDateView((prev) => {
// convert to UTC to avoid timezone issues
const date = new Date(Date.UTC(prev.getFullYear(), prev.getMonth(), prev.getDate()));
const newCurrentDateView = setDate(date, day);
const newCurrentDateView = setDate(new Date(prev), day);
onSelected?.(format(new Date(newCurrentDateView), CONST.DATE.FNS_FORMAT_STRING));
return newCurrentDateView;
});
Expand Down Expand Up @@ -152,8 +150,8 @@ function CalendarPicker({
});
};

const monthNames = DateUtils.getMonthNames(preferredLocale).map((month) => Str.UCFirst(month));
const daysOfWeek = DateUtils.getDaysOfWeek(preferredLocale).map((day) => day.toUpperCase());
const monthNames = DateUtils.getMonthNames().map((month) => Str.UCFirst(month));
const daysOfWeek = DateUtils.getDaysOfWeek().map((day) => day.toUpperCase());
const hasAvailableDatesNextMonth = startOfDay(new Date(maxDate)) > endOfMonth(new Date(currentDateView));
const hasAvailableDatesPrevMonth = endOfDay(new Date(minDate)) < startOfMonth(new Date(currentDateView));

Expand Down
40 changes: 4 additions & 36 deletions src/components/DatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import mergeRefs from '@libs/mergeRefs';
import {setDraftValues} from '@userActions/FormActions';
import CONST, {DATE_TIME_FORMAT_OPTIONS} from '@src/CONST';
import CONST from '@src/CONST';
import DatePickerModal from './DatePickerModal';
import type {DateInputWithPickerProps} from './types';

Expand Down Expand Up @@ -37,7 +37,7 @@ function DatePicker({
const icons = useMemoizedLazyExpensifyIcons(['Calendar']);
const styles = useThemeStyles();
const {windowHeight, windowWidth} = useWindowDimensions();
const {preferredLocale} = useLocalize();
const {translate} = useLocalize();
const [isModalVisible, setIsModalVisible] = useState(false);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [selectedDate, setSelectedDate] = useState(value || defaultValue || undefined);
Expand All @@ -47,38 +47,6 @@ function DatePicker({
const [isInverted, setIsInverted] = useState(false);
const isAutoFocused = useRef(false);

const formattedValue = useMemo(() => {
if (!selectedDate) {
return '';
}
const date = new Date(selectedDate);
if (Number.isNaN(date.getTime())) {
return '';
}
return Intl.DateTimeFormat(preferredLocale, DATE_TIME_FORMAT_OPTIONS[CONST.DATE.FNS_FORMAT_STRING]).format(date);
}, [selectedDate, preferredLocale]);

const computedPlaceholder = useMemo(() => {
if (placeholder) {
return placeholder;
}
return Intl.DateTimeFormat(preferredLocale, DATE_TIME_FORMAT_OPTIONS[CONST.DATE.FNS_FORMAT_STRING])
.formatToParts()
.map((part) => {
switch (part.type) {
case 'day':
return 'DD';
case 'month':
return 'MM';
case 'year':
return 'YYYY';
default:
return part.value;
}
})
.join('');
}, [placeholder, preferredLocale]);

useEffect(() => {
if (shouldSaveDraft && formID) {
setDraftValues(formID, {[inputID]: selectedDate});
Expand Down Expand Up @@ -166,8 +134,8 @@ function DatePicker({
label={label}
accessibilityLabel={label}
role={CONST.ROLE.PRESENTATION}
value={formattedValue}
placeholder={computedPlaceholder}
value={selectedDate}
placeholder={placeholder ?? translate('common.dateFormat')}
errorText={errorText}
inputStyle={styles.pointerEventsNone}
disabled={disabled}
Expand Down
10 changes: 2 additions & 8 deletions src/components/DistanceEReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils';
import {getTransactionDetails} from '@libs/ReportUtils';
import {getWaypointIndex, hasReceipt, isFetchingWaypointsFromServer} from '@libs/TransactionUtils';
import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import type {Transaction} from '@src/types/onyx';
import type {WaypointCollection} from '@src/types/onyx/Transaction';
Expand All @@ -30,15 +29,10 @@ type DistanceEReceiptProps = {

function DistanceEReceipt({transaction, hoverPreview = false}: DistanceEReceiptProps) {
const styles = useThemeStyles();
const {translate, preferredLocale} = useLocalize();
const {translate} = useLocalize();
const icons = useMemoizedLazyExpensifyIcons(['ExpensifyWordmark']);
const thumbnail = hasReceipt(transaction) ? getThumbnailAndImageURIs(transaction).thumbnail : null;
const {
amount: transactionAmount,
currency: transactionCurrency,
merchant: transactionMerchant,
created: transactionDate,
} = getTransactionDetails(transaction, CONST.DATE.FNS_FORMAT_STRING, undefined, undefined, undefined, undefined, preferredLocale) ?? {};
const {amount: transactionAmount, currency: transactionCurrency, merchant: transactionMerchant, created: transactionDate} = getTransactionDetails(transaction) ?? {};
const formattedTransactionAmount = convertToDisplayString(transactionAmount, transactionCurrency);
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail ?? '');
const waypoints = useMemo(() => transaction?.comment?.waypoints ?? {}, [transaction?.comment?.waypoints]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/EReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const backgroundImageMinWidth: number = variables.eReceiptBackgroundImageMinWidt
function EReceipt({transactionID, transactionItem, onLoad, isThumbnail = false}: EReceiptProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate, preferredLocale} = useLocalize();
const {translate} = useLocalize();
const {getCurrencySymbol} = useCurrencyList();
const theme = useTheme();
const icons = useMemoizedLazyExpensifyIcons(['ReceiptBody', 'ExpensifyWordmark']);
Expand All @@ -58,7 +58,7 @@ function EReceipt({transactionID, transactionItem, onLoad, isThumbnail = false}:
created: transactionDate,
cardID: transactionCardID,
cardName: transactionCardName,
} = getTransactionDetails(transactionItem ?? transaction, CONST.DATE.MONTH_DAY_YEAR_FORMAT, undefined, undefined, undefined, undefined, preferredLocale) ?? {};
} = getTransactionDetails(transactionItem ?? transaction, CONST.DATE.MONTH_DAY_YEAR_FORMAT) ?? {};
const formattedAmount = convertToDisplayString(transactionAmount, transactionCurrency);
const currency = getCurrencySymbol(transactionCurrency ?? '');
const amount = currency ? formattedAmount.replace(currency, '') : formattedAmount;
Expand Down
10 changes: 2 additions & 8 deletions 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 @@ -82,7 +82,7 @@

const {shouldShowProductTrainingTooltip, renderProductTrainingTooltip, hideProductTrainingTooltip} = useProductTrainingContext(tooltipToRender, shouldShowTooltip);

const {translate, preferredLocale} = useLocalize();
const {translate} = useLocalize();
const [isContextMenuActive, setIsContextMenuActive] = useState(false);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

Expand Down Expand Up @@ -163,13 +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(
translate,
statusClearAfterDate,
optionItem?.timezone?.selected ?? CONST.DEFAULT_TIME_ZONE.selected,
currentSelectedTimezone,
preferredLocale,
);
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
12 changes: 4 additions & 8 deletions src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {emailSelector} from '@selectors/Session';
import {format} from 'date-fns';
import {Str} from 'expensify-common';
import {deepEqual} from 'fast-equals';
import React, {memo, useMemo} from 'react';
Expand Down Expand Up @@ -38,7 +39,7 @@ import {
} from '@libs/TransactionUtils';
import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot';
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
import CONST, {DATE_TIME_FORMAT_OPTIONS} from '@src/CONST';
import CONST from '@src/CONST';
import type {IOUAction, IOUType} from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -283,7 +284,7 @@ function MoneyRequestConfirmationListFooter({
}: MoneyRequestConfirmationListFooterProps) {
const icons = useMemoizedLazyExpensifyIcons(['Stopwatch', 'CalendarSolid']);
const styles = useThemeStyles();
const {translate, toLocaleDigit, localeCompare, preferredLocale} = useLocalize();
const {translate, toLocaleDigit, localeCompare} = useLocalize();
const {getCurrencySymbol} = useCurrencyList();
const {isOffline} = useNetwork();

Expand All @@ -300,11 +301,6 @@ function MoneyRequestConfirmationListFooter({
const isUnreported = transaction?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
const isCreatingTrackExpense = action === CONST.IOU.ACTION.CREATE && iouType === CONST.IOU.TYPE.TRACK;

const formattedCreatedDate = useMemo(() => {
const formatter = new Intl.DateTimeFormat(preferredLocale, DATE_TIME_FORMAT_OPTIONS[CONST.DATE.FNS_FORMAT_STRING]);
return formatter.format(new Date(iouCreated ?? Date.now()));
}, [iouCreated, preferredLocale]);

const decodedCategoryName = useMemo(() => getDecodedCategoryName(iouCategory), [iouCategory]);

const allOutstandingReports = useMemo(() => {
Expand Down Expand Up @@ -698,7 +694,7 @@ function MoneyRequestConfirmationListFooter({
key={translate('common.date')}
shouldShowRightIcon={!isReadOnly}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
title={formattedCreatedDate}
title={iouCreated || format(new Date(), CONST.DATE.FNS_FORMAT_STRING)}
description={translate('common.date')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
Expand Down
8 changes: 2 additions & 6 deletions src/components/PerDiemEReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function getPerDiemDates(merchant: string) {
function PerDiemEReceipt({transactionID}: PerDiemEReceiptProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate, preferredLocale} = useLocalize();
const {translate} = useLocalize();
const {getCurrencySymbol} = useCurrencyList();
const icons = useMemoizedLazyExpensifyIcons(['ExpensifyWordmark']);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`, {
Expand All @@ -62,11 +62,7 @@ function PerDiemEReceipt({transactionID}: PerDiemEReceiptProps) {
// Get receipt colorway, or default to Yellow.
const {backgroundColor: primaryColor, color: secondaryColor} = StyleUtils.getEReceiptColorStyles(StyleUtils.getEReceiptColorCode(transaction)) ?? {};

const {
amount: transactionAmount,
currency: transactionCurrency,
merchant: transactionMerchant,
} = getTransactionDetails(transaction, CONST.DATE.MONTH_DAY_YEAR_FORMAT, undefined, undefined, undefined, undefined, preferredLocale) ?? {};
const {amount: transactionAmount, currency: transactionCurrency, merchant: transactionMerchant} = getTransactionDetails(transaction, CONST.DATE.MONTH_DAY_YEAR_FORMAT) ?? {};
const ratesDescription = computeDefaultPerDiemExpenseRates(transaction?.comment?.customUnit ?? {}, transactionCurrency ?? '');
const datesDescription = getPerDiemDates(transactionMerchant ?? '');
const destination = getPerDiemDestination(transactionMerchant ?? '');
Expand Down
8 changes: 4 additions & 4 deletions src/components/ReportActionItem/ChronosOOOListActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ChronosOOOListActionsProps = {
function ChronosOOOListActions({reportID, action}: ChronosOOOListActionsProps) {
const styles = useThemeStyles();

const {translate, getLocalDateFromDatetime, preferredLocale} = useLocalize();
const {translate, getLocalDateFromDatetime} = useLocalize();

const events = getOriginalMessage(action)?.events ?? [];

Expand Down Expand Up @@ -50,12 +50,12 @@ function ChronosOOOListActions({reportID, action}: ChronosOOOListActionsProps) {
? translate('chronos.oooEventSummaryFullDay', {
summary: event.summary,
dayCount: event.lengthInDays,
date: DateUtils.formatToLongDateWithWeekday(end, preferredLocale),
date: DateUtils.formatToLongDateWithWeekday(end),
})
: translate('chronos.oooEventSummaryPartialDay', {
summary: event.summary,
timePeriod: `${DateUtils.formatToLocalTime(start, preferredLocale)} - ${DateUtils.formatToLocalTime(end, preferredLocale)}`,
date: DateUtils.formatToLongDateWithWeekday(end, preferredLocale),
timePeriod: `${DateUtils.formatToLocalTime(start)} - ${DateUtils.formatToLocalTime(end)}`,
date: DateUtils.formatToLongDateWithWeekday(end),
})}
</Text>
<Button
Expand Down
Loading
Loading