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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jest.mock('@metamask/design-system-react-native', () => ({
}));

jest.mock('../../../../../../locales/i18n', () => ({
__esModule: true,
default: { locale: 'en-US' },
strings: jest.fn((key: string, params?: Record<string, string>) =>
params ? `${key}:${JSON.stringify(params)}` : key,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
type CampaignDto,
type CampaignStatus,
} from '../../../../../core/Engine/controllers/rewards-controller/types';
import { strings } from '../../../../../../locales/i18n';
import I18n, { strings } from '../../../../../../locales/i18n';
import { getIntlDateTimeFormatter } from '../../../../../util/intl';

/**
* Set of campaign types that have full UI support (details view, opt-in, etc.)
Expand Down Expand Up @@ -53,32 +54,18 @@ export function getCampaignStatus(campaign: CampaignDto): CampaignStatus {
return 'complete';
}

const MONTHS = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

/**
* Formats a date for display in campaign tiles.
* Formats a date for display in campaign tiles (localized month and day).
*
* @param date - The date to format
* @returns Formatted date string (e.g., "March 15")
* @param locale - BCP 47 locale; defaults to the app locale
* @returns Formatted date string (e.g., "March 15" in en-US)
*/
function formatCampaignDate(date: Date): string {
const month = MONTHS[date.getMonth()];
const day = date.getDate();

return `${month} ${day}`;
function formatCampaignDate(date: Date, locale: string = I18n.locale): string {
return getIntlDateTimeFormatter(locale, {
month: 'long',
day: 'numeric',
}).format(date);
}

/**
Expand Down
Loading