Skip to content

Commit

Permalink
(core) Fixing billing tests
Browse files Browse the repository at this point in the history
Summary: Fixing date formatting issue in billing tests.

Test Plan: Existing

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D4421
  • Loading branch information
berhalak committed Jan 9, 2025
1 parent ffc4855 commit 2c0376a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/client/lib/textUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,32 @@ export function simpleStringHash(str: string) {
}
return result;
}

/**
* Formats a timestamp in milliseconds to a short or full date string.
* Uses full date format if the year is different from the current year.
*/
export function dateFmt(timestampMs: number | null): string {
if (!timestampMs) { return "unknown"; }
const date = new Date(timestampMs);
if (date.getFullYear() !== new Date().getFullYear()) {
return dateFmtFull(timestampMs);
}
return new Date(timestampMs).toLocaleDateString('default', { month: 'long', day: 'numeric' });
}

/**
* Formats a timestamp in milliseconds to a full date string.
*/
export function dateFmtFull(timestampMs: number | null): string {
if (!timestampMs) { return "unknown"; }
return new Date(timestampMs).toLocaleDateString('default', { month: 'short', day: 'numeric', year: 'numeric' });
}

/**
* Formats a timestamp in milliseconds to a time string.
*/
export function timeFmt(timestampMs: number): string {
return new Date(timestampMs).toLocaleString('default',
{ month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' });
}

0 comments on commit 2c0376a

Please sign in to comment.