Skip to content

Commit 29e86c3

Browse files
committed
fix: error with date
1 parent c513115 commit 29e86c3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/utils/get-formatted-date.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
export type TGetFormattedDate = (timestamp?: number) => string;
22

3-
export const getFormattedDate: TGetFormattedDate = (
4-
timestamp = Date.now()
5-
): string => {
6-
const now = new Date(timestamp);
3+
export const getFormattedDate: TGetFormattedDate = (timestamp): string => {
4+
const date = timestamp ? new Date(timestamp * 1000) : new Date();
5+
76
const daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
87
const months = [
98
'Jan',
@@ -20,9 +19,9 @@ export const getFormattedDate: TGetFormattedDate = (
2019
'Dec',
2120
];
2221

23-
const dayOfWeek = daysOfWeek[now.getDay()];
24-
const month = months[now.getMonth()];
25-
const day = now.getDate();
22+
const dayOfWeek = daysOfWeek[date.getDay()];
23+
const month = months[date.getMonth()];
24+
const day = date.getDate();
2625

2726
return `${dayOfWeek} ${month} ${day}`;
2827
};

0 commit comments

Comments
 (0)