mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 05:59:35 +01:00
core: format time correctly
This commit is contained in:
committed by
Abdullah Atta
parent
58f7a206d9
commit
c85242a610
@@ -148,20 +148,21 @@ export function formatReminderTime(
|
|||||||
if (reminder.mode === "repeat") {
|
if (reminder.mode === "repeat") {
|
||||||
time = getUpcomingReminderTime(reminder);
|
time = getUpcomingReminderTime(reminder);
|
||||||
}
|
}
|
||||||
|
const timeFormat = options.timeFormat === "12-hour" ? "h:mm A" : "HH:mm";
|
||||||
|
|
||||||
if (dayjs(time).isTomorrow()) {
|
if (dayjs(time).isTomorrow()) {
|
||||||
tag = "Upcoming";
|
tag = "Upcoming";
|
||||||
text = `Tomorrow, ${dayjs(time).format(options.timeFormat)}`;
|
text = `Tomorrow, ${dayjs(time).format(timeFormat)}`;
|
||||||
} else if (dayjs(time).isYesterday()) {
|
} else if (dayjs(time).isYesterday()) {
|
||||||
tag = "Last";
|
tag = "Last";
|
||||||
text = `Yesterday, ${dayjs(time).format(options.timeFormat)}`;
|
text = `Yesterday, ${dayjs(time).format(timeFormat)}`;
|
||||||
} else {
|
} else {
|
||||||
const isPast = dayjs(time).isSameOrBefore(dayjs());
|
const isPast = dayjs(time).isSameOrBefore(dayjs());
|
||||||
tag = isPast ? "Last" : "Upcoming";
|
tag = isPast ? "Last" : "Upcoming";
|
||||||
if (dayjs(time).isToday()) {
|
if (dayjs(time).isToday()) {
|
||||||
text = `Today, ${dayjs(time).format(options.timeFormat)}`;
|
text = `Today, ${dayjs(time).format(timeFormat)}`;
|
||||||
} else {
|
} else {
|
||||||
text = dayjs(time).format(options.dateFormat);
|
text = dayjs(time).format(`${options.dateFormat} ${timeFormat}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,17 +77,12 @@ export function formatDate(
|
|||||||
type: "date-time"
|
type: "date-time"
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
const timeFormat = options.timeFormat === "12-hour" ? "h:mm A" : "HH:mm";
|
||||||
switch (options.type) {
|
switch (options.type) {
|
||||||
case "date-time":
|
case "date-time":
|
||||||
return dayjs(date).format(
|
return dayjs(date).format(`${options.dateFormat} ${timeFormat}`);
|
||||||
`${options.dateFormat} ${
|
|
||||||
options.timeFormat === "12-hour" ? "h:mm A" : "HH:mm"
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
case "time":
|
case "time":
|
||||||
return dayjs(date).format(
|
return dayjs(date).format(timeFormat);
|
||||||
`${options.timeFormat === "12-hour" ? "h:mm A" : "HH:mm"}`
|
|
||||||
);
|
|
||||||
case "date":
|
case "date":
|
||||||
return dayjs(date).format(`${options.dateFormat}`);
|
return dayjs(date).format(`${options.dateFormat}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user