Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add code comments to better describe date formatting util #29242

Merged
merged 5 commits into from
Feb 19, 2025
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
4 changes: 2 additions & 2 deletions ui/helpers/utils/notification.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ export function formatMenuItemDate(date: Date) {
);
}

// E.g. 21 Oct
// E.g. Oct 21
if (isSameYear(currentDate, date)) {
return new Intl.DateTimeFormat('en', {
month: 'short',
day: 'numeric',
}).format(date);
}

// E.g. 21 Oct 2022
// E.g. Oct 21, 2022
return new Intl.DateTimeFormat('en', {
year: 'numeric',
month: 'short',
Expand Down
10 changes: 5 additions & 5 deletions ui/helpers/utils/notification.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('formatMenuItemDate', () => {
const assertToday = (modifyDate?: (d: Date) => void) => {
const testDate = new Date();
modifyDate?.(testDate);
expect(formatMenuItemDate(testDate)).toMatch(/^\d{2}:\d{2}$/u);
expect(formatMenuItemDate(testDate)).toMatch(/^\d{2}:\d{2}$/u); // E.g. HH:mm
};

// assert current date
Expand Down Expand Up @@ -53,11 +53,11 @@ describe('formatMenuItemDate', () => {
});
});

it('should format date as "DD Mon" if the date is this year but not today or yesterday', () => {
it('should format date as "MM DD" if the date is this year but not today or yesterday', () => {
const assertMonthsAgo = (modifyDate: (d: Date) => Date | void) => {
let testDate = new Date();
testDate = modifyDate(testDate) ?? testDate;
expect(formatMenuItemDate(testDate)).toMatch(/^\w{3} \d{1,2}$/u);
expect(formatMenuItemDate(testDate)).toMatch(/^\w{3} \d{1,2}$/u); // E.g. Oct 21
};

// assert exactly 1 month ago
Expand All @@ -77,11 +77,11 @@ describe('formatMenuItemDate', () => {
});
});

it('should format date as "Mon DD, YYYY" if the date is not this year', () => {
it('should format date as "MM DD, YYYY" if the date is not this year', () => {
const assertYearsAgo = (modifyDate: (d: Date) => Date | void) => {
let testDate = new Date();
testDate = modifyDate(testDate) ?? testDate;
expect(formatMenuItemDate(testDate)).toMatch(/^\w{3} \d{1,2}, \d{4}$/u);
expect(formatMenuItemDate(testDate)).toMatch(/^\w{3} \d{1,2}, \d{4}$/u); // E.g. Oct 21, 2022
};

// assert exactly 1 year ago
Expand Down
Loading