mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
The start and end dates of the maintenance are now stored in UTC, which allows it to be converted between time zones
This commit is contained in:
parent
5fda1f0f59
commit
e7b2832967
6 changed files with 33 additions and 34 deletions
|
@ -29,7 +29,7 @@ class Monitor extends BeanModel {
|
||||||
* Only show necessary data to public
|
* Only show necessary data to public
|
||||||
*/
|
*/
|
||||||
async toPublicJSON() {
|
async toPublicJSON() {
|
||||||
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now', 'localtime') AND datetime(maintenance.end_date) >= datetime('now', 'localtime')", [this.id]);
|
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now') AND datetime(maintenance.end_date) >= datetime('now')", [this.id]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
@ -54,7 +54,7 @@ class Monitor extends BeanModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
const tags = await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [this.id]);
|
const tags = await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [this.id]);
|
||||||
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now', 'localtime') AND datetime(maintenance.end_date) >= datetime('now', 'localtime')", [this.id]);
|
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now') AND datetime(maintenance.end_date) >= datetime('now')", [this.id]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
|
@ -142,7 +142,7 @@ class Monitor extends BeanModel {
|
||||||
bean.time = R.isoDateTime(dayjs.utc());
|
bean.time = R.isoDateTime(dayjs.utc());
|
||||||
bean.status = DOWN;
|
bean.status = DOWN;
|
||||||
|
|
||||||
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now', 'localtime') AND datetime(maintenance.end_date) >= datetime('now', 'localtime')", [this.id]);
|
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now') AND datetime(maintenance.end_date) >= datetime('now')", [this.id]);
|
||||||
|
|
||||||
if (this.isUpsideDown()) {
|
if (this.isUpsideDown()) {
|
||||||
bean.status = flipStatus(bean.status);
|
bean.status = flipStatus(bean.status);
|
||||||
|
|
|
@ -51,7 +51,7 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
||||||
duration = dayjs(bean.time).diff(dayjs(previousHeartbeat.time), "second");
|
duration = dayjs(bean.time).diff(dayjs(previousHeartbeat.time), "second");
|
||||||
}
|
}
|
||||||
|
|
||||||
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now', 'localtime') AND datetime(maintenance.end_date) >= datetime('now', 'localtime')", [monitor.id]);
|
const maintenance = await R.getAll("SELECT mm.*, maintenance.start_date, maintenance.end_date FROM monitor_maintenance mm JOIN maintenance ON mm.maintenance_id = maintenance.id WHERE mm.monitor_id = ? AND datetime(maintenance.start_date) <= datetime('now') AND datetime(maintenance.end_date) >= datetime('now')", [monitor.id]);
|
||||||
if (maintenance.length !== 0) {
|
if (maintenance.length !== 0) {
|
||||||
msg = "Monitor under maintenance";
|
msg = "Monitor under maintenance";
|
||||||
status = MAINTENANCE;
|
status = MAINTENANCE;
|
||||||
|
@ -149,8 +149,8 @@ router.get("/api/status-page/maintenance-list", async (_request, response) => {
|
||||||
let maintenanceBeanList = R.convertToBeans("maintenance", await R.getAll(`
|
let maintenanceBeanList = R.convertToBeans("maintenance", await R.getAll(`
|
||||||
SELECT maintenance.*
|
SELECT maintenance.*
|
||||||
FROM maintenance
|
FROM maintenance
|
||||||
WHERE datetime(maintenance.start_date) <= datetime('now', 'localtime')
|
WHERE datetime(maintenance.start_date) <= datetime('now')
|
||||||
AND datetime(maintenance.end_date) >= datetime('now', 'localtime')
|
AND datetime(maintenance.end_date) >= datetime('now')
|
||||||
ORDER BY maintenance.end_date
|
ORDER BY maintenance.end_date
|
||||||
`));
|
`));
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
{{ $t("No Maintenance, please") }} <router-link to="/addMaintenance">{{ $t("add one") }}</router-link>
|
{{ $t("No Maintenance, please") }} <router-link to="/addMaintenance">{{ $t("add one") }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<router-link v-if="selectedList === 'maintenance'" v-for="(item, index) in sortedMaintenanceList" :key="index" :to="maintenanceURL(item.id)" class="item" :class="{ 'disabled': (Date.parse(item.end_date) < Date.now()) }">
|
<router-link v-if="selectedList === 'maintenance'" v-for="(item, index) in sortedMaintenanceList" :key="index" :to="maintenanceURL(item.id)" class="item" :class="{ 'disabled': !this.$root.isActiveMaintenance(item.end_date) }">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-9 col-md-8 small-padding">
|
<div class="col-9 col-md-8 small-padding">
|
||||||
<div class="info">
|
<div class="info">
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
import HeartbeatBar from "../components/HeartbeatBar.vue";
|
import HeartbeatBar from "../components/HeartbeatBar.vue";
|
||||||
import Uptime from "../components/Uptime.vue";
|
import Uptime from "../components/Uptime.vue";
|
||||||
import Tag from "../components/Tag.vue";
|
import Tag from "../components/Tag.vue";
|
||||||
import {getMaintenanceRelativeURL, getMonitorRelativeURL } from "../util.ts";
|
import { getMaintenanceRelativeURL, getMonitorRelativeURL } from "../util.ts";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -90,18 +90,17 @@ export default {
|
||||||
let result = Object.values(this.$root.maintenanceList);
|
let result = Object.values(this.$root.maintenanceList);
|
||||||
|
|
||||||
result.sort((m1, m2) => {
|
result.sort((m1, m2) => {
|
||||||
const now = Date.now();
|
|
||||||
|
|
||||||
if (Date.parse(m1.end_date) >= now !== Date.parse(m2.end_date) >= now) {
|
if (this.$root.isActiveMaintenance(m1.end_date) !== this.$root.isActiveMaintenance(m2.end_date)) {
|
||||||
if (Date.parse(m2.end_date) < now) {
|
if (!this.$root.isActiveMaintenance(m2.end_date)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (Date.parse(m1.end_date) < now) {
|
if (!this.$root.isActiveMaintenance(m1.end_date)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Date.parse(m1.end_date) >= now && Date.parse(m2.end_date) >= now) {
|
if (this.$root.isActiveMaintenance(m1.end_date) && this.$root.isActiveMaintenance(m2.end_date)) {
|
||||||
if (Date.parse(m1.end_date) < Date.parse(m2.end_date)) {
|
if (Date.parse(m1.end_date) < Date.parse(m2.end_date)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +110,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Date.parse(m1.end_date) < now && Date.parse(m2.end_date) < now) {
|
if (!this.$root.isActiveMaintenance(m1.end_date) && !this.$root.isActiveMaintenance(m2.end_date)) {
|
||||||
if (Date.parse(m1.end_date) < Date.parse(m2.end_date)) {
|
if (Date.parse(m1.end_date) < Date.parse(m2.end_date)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,14 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
isActiveMaintenance(endDate) {
|
||||||
|
return (dayjs.utc(endDate).unix() >= dayjs.utc().unix());
|
||||||
|
},
|
||||||
|
|
||||||
|
toUTC(value) {
|
||||||
|
return dayjs.tz(value, this.timezone).utc().format();
|
||||||
|
},
|
||||||
|
|
||||||
datetime(value) {
|
datetime(value) {
|
||||||
return this.datetimeFormat(value, "YYYY-MM-DD HH:mm:ss");
|
return this.datetimeFormat(value, "YYYY-MM-DD HH:mm:ss");
|
||||||
},
|
},
|
||||||
|
@ -26,10 +34,10 @@ export default {
|
||||||
const inputDate = new Date(value);
|
const inputDate = new Date(value);
|
||||||
const now = new Date(Date.now());
|
const now = new Date(Date.now());
|
||||||
|
|
||||||
if (inputDate.getFullYear() === now.getFullYear() && inputDate.getMonth() === now.getMonth() && inputDate.getDay() === now.getDay())
|
if (inputDate.getFullYear() === now.getUTCFullYear() && inputDate.getMonth() === now.getUTCMonth() && inputDate.getDay() === now.getUTCDay())
|
||||||
return this.datetimeMaintenanceFormat(value, "HH:mm");
|
return this.datetimeFormat(value, "HH:mm");
|
||||||
else
|
else
|
||||||
return this.datetimeMaintenanceFormat(value, "YYYY-MM-DD HH:mm");
|
return this.datetimeFormat(value, "YYYY-MM-DD HH:mm");
|
||||||
},
|
},
|
||||||
|
|
||||||
date(value) {
|
date(value) {
|
||||||
|
@ -52,13 +60,6 @@ export default {
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
|
|
||||||
datetimeMaintenanceFormat(value, format) {
|
|
||||||
if (value !== undefined && value !== "") {
|
|
||||||
return dayjs(value).format(format);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
|
|
@ -50,14 +50,14 @@
|
||||||
|
|
||||||
<!-- Start Date Time -->
|
<!-- Start Date Time -->
|
||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
<label for="start_date" class="form-label">{{ $t("Start of maintenance") }}</label>
|
<label for="start_date" class="form-label">{{ $t("Start of maintenance") }} ({{this.$root.timezone}})</label>
|
||||||
<input :type="'datetime-local'" id="start_date" v-model="maintenance.start_date"
|
<input :type="'datetime-local'" id="start_date" v-model="maintenance.start_date"
|
||||||
class="form-control" :class="{'darkCalendar': dark }" required>
|
class="form-control" :class="{'darkCalendar': dark }" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- End Date Time -->
|
<!-- End Date Time -->
|
||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
<label for="end_date" class="form-label">{{ $t("Expected end of maintenance") }}</label>
|
<label for="end_date" class="form-label">{{ $t("Expected end of maintenance") }} ({{this.$root.timezone}})</label>
|
||||||
<input :type="'datetime-local'" id="end_date" v-model="maintenance.end_date"
|
<input :type="'datetime-local'" id="end_date" v-model="maintenance.end_date"
|
||||||
class="form-control" :class="{'darkCalendar': dark }" required>
|
class="form-control" :class="{'darkCalendar': dark }" required>
|
||||||
</div>
|
</div>
|
||||||
|
@ -156,6 +156,8 @@ export default {
|
||||||
} else if (this.isEdit) {
|
} else if (this.isEdit) {
|
||||||
this.$root.getSocket().emit("getMaintenance", this.$route.params.id, (res) => {
|
this.$root.getSocket().emit("getMaintenance", this.$route.params.id, (res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
res.maintenance.start_date = this.$root.datetimeFormat(res.maintenance.start_date, "YYYY-MM-DDTHH:mm");
|
||||||
|
res.maintenance.end_date = this.$root.datetimeFormat(res.maintenance.end_date, "YYYY-MM-DDTHH:mm");
|
||||||
this.maintenance = res.maintenance;
|
this.maintenance = res.maintenance;
|
||||||
|
|
||||||
this.$root.getSocket().emit("getMonitorMaintenance", this.$route.params.id, (res) => {
|
this.$root.getSocket().emit("getMonitorMaintenance", this.$route.params.id, (res) => {
|
||||||
|
@ -182,9 +184,11 @@ export default {
|
||||||
return this.processing = false;
|
return this.processing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.maintenance.start_date = this.$root.toUTC(this.maintenance.start_date);
|
||||||
|
this.maintenance.end_date = this.$root.toUTC(this.maintenance.end_date);
|
||||||
|
|
||||||
if (this.isAdd) {
|
if (this.isAdd) {
|
||||||
this.$root.addMaintenance(this.maintenance, async (res) => {
|
this.$root.addMaintenance(this.maintenance, async (res) => {
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
await this.addMonitorMaintenance(res.maintenanceID, () => {
|
await this.addMonitorMaintenance(res.maintenanceID, () => {
|
||||||
toast.success(res.msg);
|
toast.success(res.msg);
|
||||||
|
@ -206,8 +210,7 @@ export default {
|
||||||
this.$root.toastRes(res);
|
this.$root.toastRes(res);
|
||||||
this.init();
|
this.init();
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.processing = false;
|
this.processing = false;
|
||||||
toast.error(res.msg);
|
toast.error(res.msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@
|
||||||
|
|
||||||
<!-- Incident Date -->
|
<!-- Incident Date -->
|
||||||
<div class="date mt-3">
|
<div class="date mt-3">
|
||||||
{{ $t("End") }}: {{ $root.datetimeMaintenance(maintenanceItem.end_date) }} ({{ dateFromNowMaintenance(maintenanceItem.start_date) }})<br />
|
{{ $t("End") }}: {{ $root.datetimeMaintenance(maintenanceItem.end_date) }} ({{ dateFromNow(maintenanceItem.start_date) }})<br />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -620,10 +620,6 @@ export default {
|
||||||
return dayjs.utc(date).fromNow();
|
return dayjs.utc(date).fromNow();
|
||||||
},
|
},
|
||||||
|
|
||||||
dateFromNowMaintenance(date) {
|
|
||||||
return dayjs(date).fromNow();
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue