Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add: utils for date and price format
  • Loading branch information
htnghia1423 committed Apr 29, 2025
commit ede925d590ec56c74118e842d463a6a050c68b19
12 changes: 12 additions & 0 deletions src/utils/dateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const formatDate = (dateString: string): string => {
if (!dateString) return 'Invalid Date';

const date = new Date(dateString);
if (isNaN(date.getTime())) return 'Invalid Date';

return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
});
};
11 changes: 11 additions & 0 deletions src/utils/priceUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Formats a number into a price string with commas as thousand separators.
* @param value - The number to format.
* @returns The formatted price string.
*/
export const formatPrice = (value: number): string => {
return value.toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
});
};