Add last updated to note pages

This commit is contained in:
2024-10-10 01:58:33 -04:00
parent c2e1817567
commit 7500465542
4 changed files with 31 additions and 2 deletions

View File

@@ -14,6 +14,16 @@ const months = [
'December'
];
function get12HourTime(pdate: Date | string): string {
const date = (typeof pdate === 'string') ? new Date(pdate) : pdate;
if (date.getHours() > 12)
return `${date.getHours() - 12}:${date.getMinutes()} PM`;
else if (date.getHours() === 0)
return `12:${date.getMinutes()} AM`;
return `${date.getHours()}:${date.getMinutes()} AM`;
}
function toHumanReadableDate(date: Date | string, disable?: { year?: boolean, month?: boolean, day?: boolean }) {
const oDate = (typeof date === 'string') ? new Date(date) : date;
@@ -29,7 +39,7 @@ function toHumanReadableDate(date: Date | string, disable?: { year?: boolean, mo
}
export function getOrdinalDaySuffix(day: number) {
export function getOrdinalDaySuffix(day: number): string {
switch (day) {
case 1:
case 21:
@@ -46,6 +56,11 @@ export function getOrdinalDaySuffix(day: number) {
}
}
export function toLocaleString(pdate: Date | string): string {
const date = (typeof pDate === 'string') ? new Date(pdate) : pdate;
return `${toHumanReadableDate(date)}, ${get12HourTime(date)}`;
}
export function toRelativeDate(date: Date | string): string {
const oDate = (typeof date === 'string') ? new Date(date) : date;
@@ -100,6 +115,7 @@ const DateTool = {
getFullMonth,
isValid,
getOrdinalDaySuffix,
toLocaleString,
};
export default DateTool;