update time format function
This commit is contained in:
1 parent
f15cef4916
commit
1298b23844
2 files changed
+29
-16
No files matched your search
@@ -80,7 +80,7 @@ const UptimeStatusBoxes = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
UptimeStatusBoxes.propTypes = {
|
UptimeStatusBoxes.propTypes = {
|
||||||
shouldRender: PropTypes.bool,
|
isLoading: PropTypes.bool,
|
||||||
monitor: PropTypes.object,
|
monitor: PropTypes.object,
|
||||||
monitorStats: PropTypes.object,
|
monitorStats: PropTypes.object,
|
||||||
certificateExpiry: PropTypes.string,
|
certificateExpiry: PropTypes.string,
|
||||||
|
|||||||
@@ -79,22 +79,35 @@ export const formatDurationSplit = (ms) => {
|
|||||||
|
|
||||||
export const getHumanReadableDuration = (ms) => {
|
export const getHumanReadableDuration = (ms) => {
|
||||||
const durationObj = dayjs.duration(ms);
|
const durationObj = dayjs.duration(ms);
|
||||||
if (durationObj.asDays() >= 1) {
|
|
||||||
const days = Math.floor(durationObj.asDays());
|
const parts = {
|
||||||
return { time: days, units: days === 1 ? "day" : "days" };
|
days: Math.floor(durationObj.asDays()),
|
||||||
} else if (durationObj.asHours() >= 1) {
|
hours: durationObj.hours(),
|
||||||
const hoursRounded = Math.round(durationObj.asHours() * 10) / 10;
|
minutes: durationObj.minutes(),
|
||||||
const hours = Number.isInteger(hoursRounded)
|
seconds: durationObj.seconds(),
|
||||||
? Math.floor(hoursRounded)
|
};
|
||||||
: hoursRounded;
|
|
||||||
return { time: hours, units: hours <= 1 ? "hour" : "hours" };
|
const result = [];
|
||||||
} else if (durationObj.asMinutes() >= 1) {
|
|
||||||
const minutes = Math.floor(durationObj.asMinutes());
|
if (parts.days > 0) {
|
||||||
return { time: minutes, units: minutes === 1 ? "minute" : "minutes" };
|
result.push(`${parts.days}d`);
|
||||||
} else {
|
|
||||||
const seconds = Math.floor(durationObj.asSeconds());
|
|
||||||
return { time: seconds, units: seconds === 1 ? "second" : "seconds" };
|
|
||||||
}
|
}
|
||||||
|
if (parts.hours > 0) {
|
||||||
|
result.push(`${parts.hours}h`);
|
||||||
|
}
|
||||||
|
if (result.length < 2 && parts.minutes > 0) {
|
||||||
|
result.push(`${parts.minutes}m`);
|
||||||
|
}
|
||||||
|
if (result.length < 2 && parts.seconds > 0) {
|
||||||
|
result.push(`${parts.seconds}s`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
// fallback for durations < 1s
|
||||||
|
return { time: 0, units: "seconds" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { time: result.join(" "), units: null };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatDate = (date, customOptions) => {
|
export const formatDate = (date, customOptions) => {
|
||||||
|
|||||||
Reference in new issue
Block a user