mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Improve code readability by formatting function arguments and return values in date handling methods
This commit is contained in:
@@ -201,12 +201,18 @@ export default class OneUptimeDate {
|
||||
return this.secondsToFormattedFriendlyTimeString(seconds);
|
||||
}
|
||||
|
||||
public static toTimeString(date: Date | string, use12HourFormat?: boolean): string {
|
||||
public static toTimeString(
|
||||
date: Date | string,
|
||||
use12HourFormat?: boolean,
|
||||
): string {
|
||||
if (typeof date === "string") {
|
||||
date = this.fromString(date);
|
||||
}
|
||||
|
||||
const format = use12HourFormat || this.getUserPrefers12HourFormat() ? "hh:mm A" : "HH:mm";
|
||||
const format =
|
||||
use12HourFormat || this.getUserPrefers12HourFormat()
|
||||
? "hh:mm A"
|
||||
: "HH:mm";
|
||||
return moment(date).format(format);
|
||||
}
|
||||
|
||||
@@ -890,11 +896,14 @@ export default class OneUptimeDate {
|
||||
// Server-side: default to 12-hour format for user-friendly display
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Client-side: detect user's preferred time format from browser locale
|
||||
const testDate = new Date();
|
||||
const timeString = testDate.toLocaleTimeString();
|
||||
return timeString.toLowerCase().includes('am') || timeString.toLowerCase().includes('pm');
|
||||
return (
|
||||
timeString.toLowerCase().includes("am") ||
|
||||
timeString.toLowerCase().includes("pm")
|
||||
);
|
||||
}
|
||||
|
||||
public static getDateAsUserFriendlyFormattedString(
|
||||
@@ -1113,7 +1122,8 @@ export default class OneUptimeDate {
|
||||
let date: string | Date = data.date;
|
||||
const onlyShowDate: boolean | undefined = data.onlyShowDate;
|
||||
let timezones: Array<Timezone> | undefined = data.timezones;
|
||||
const use12HourFormat: boolean = data.use12HourFormat ?? this.getUserPrefers12HourFormat();
|
||||
const use12HourFormat: boolean =
|
||||
data.use12HourFormat ?? this.getUserPrefers12HourFormat();
|
||||
|
||||
date = this.fromString(date);
|
||||
|
||||
|
||||
@@ -55,7 +55,10 @@ const EventHistoryDayList: FunctionComponent<ComponentProps> = (
|
||||
width: isMobile ? "100%" : "15%",
|
||||
}}
|
||||
>
|
||||
{OneUptimeDate.getDateAsUserFriendlyLocalFormattedString(props.date, true)}
|
||||
{OneUptimeDate.getDateAsUserFriendlyLocalFormattedString(
|
||||
props.date,
|
||||
true,
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
|
||||
@@ -144,7 +144,8 @@ const LogItem: FunctionComponent<ComponentProps> = (
|
||||
DATE TIME:
|
||||
</div>
|
||||
<div className="text-slate-500 courier-prime">
|
||||
{OneUptimeDate.getDateAsUserFriendlyFormattedString(props.log.time)} {" "}
|
||||
{OneUptimeDate.getDateAsUserFriendlyFormattedString(props.log.time)}{" "}
|
||||
{" "}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -88,7 +88,9 @@ const CustomMonitorSummaryView: FunctionComponent<ComponentProps> = (
|
||||
title="Monitored At"
|
||||
value={
|
||||
props.monitoredAt
|
||||
? OneUptimeDate.getDateAsUserFriendlyLocalFormattedString(props.monitoredAt)
|
||||
? OneUptimeDate.getDateAsUserFriendlyLocalFormattedString(
|
||||
props.monitoredAt,
|
||||
)
|
||||
: "-"
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -175,7 +175,11 @@ const TraceExplorer: FunctionComponent<ComponentProps> = (
|
||||
</div>
|
||||
<div className="">
|
||||
<div className="font-semibold">Seen at:</div>{" "}
|
||||
<div>{OneUptimeDate.getDateAsUserFriendlyFormattedString(span.startTime!)}</div>
|
||||
<div>
|
||||
{OneUptimeDate.getDateAsUserFriendlyFormattedString(
|
||||
span.startTime!,
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="">
|
||||
<div className="font-semibold">Start:</div>{" "}
|
||||
|
||||
@@ -209,7 +209,9 @@ export const getIncidentEventItem: GetIncidentEventItemFunction = (
|
||||
anotherStatus: incident.incidentSeverity?.name,
|
||||
eventSecondDescription: incident.createdAt
|
||||
? "Created at " +
|
||||
OneUptimeDate.getDateAsUserFriendlyLocalFormattedString(incident.createdAt!)
|
||||
OneUptimeDate.getDateAsUserFriendlyLocalFormattedString(
|
||||
incident.createdAt!,
|
||||
)
|
||||
: "",
|
||||
eventTypeColor: Red,
|
||||
labels:
|
||||
|
||||
@@ -419,9 +419,10 @@ RunCron(
|
||||
})
|
||||
.join(", ") || "",
|
||||
|
||||
scheduledAt: OneUptimeDate.getDateAsUserFriendlyFormattedString(
|
||||
event.startsAt!,
|
||||
),
|
||||
scheduledAt:
|
||||
OneUptimeDate.getDateAsUserFriendlyFormattedString(
|
||||
event.startsAt!,
|
||||
),
|
||||
eventTitle: event.title || "",
|
||||
eventDescription: event.description || "",
|
||||
unsubscribeUrl: unsubscribeUrl,
|
||||
|
||||
@@ -381,9 +381,10 @@ RunCron(
|
||||
scheduledEventStateTimeline.scheduledMaintenanceState
|
||||
?.name || "",
|
||||
|
||||
scheduledAt: OneUptimeDate.getDateAsUserFriendlyFormattedString(
|
||||
event.startsAt!,
|
||||
),
|
||||
scheduledAt:
|
||||
OneUptimeDate.getDateAsUserFriendlyFormattedString(
|
||||
event.startsAt!,
|
||||
),
|
||||
eventTitle: event.title || "",
|
||||
unsubscribeUrl: unsubscribeUrl,
|
||||
subscriberEmailNotificationFooterText:
|
||||
|
||||
Reference in New Issue
Block a user