feat: move scripts to script folder
This commit is contained in:
28
src/scripts/time.ts
Normal file
28
src/scripts/time.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
function formatFromNow(date: Date | null): string {
|
||||
if (!date) {
|
||||
return 'none';
|
||||
}
|
||||
return dayjs(date).fromNow()
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
return new Date(date).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
}
|
||||
|
||||
function formatShortDate(date: Date): string {
|
||||
return new Date(date).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
}
|
||||
|
||||
export { formatFromNow, formatDate, formatShortDate, };
|
||||
Reference in New Issue
Block a user