mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-04 13:46:13 +08:00 
			
		
		
		
	Change DateTime Range using serverTimezone
This commit is contained in:
		@@ -4,7 +4,8 @@
 | 
			
		||||
const { TimeLogger } = require("../src/util");
 | 
			
		||||
const { R } = require("redbean-node");
 | 
			
		||||
const { UptimeKumaServer } = require("./uptime-kuma-server");
 | 
			
		||||
const io = UptimeKumaServer.getInstance().io;
 | 
			
		||||
const server = UptimeKumaServer.getInstance();
 | 
			
		||||
const io = server.io;
 | 
			
		||||
const { setting } = require("./util-server");
 | 
			
		||||
const checkVersion = require("./check-version");
 | 
			
		||||
 | 
			
		||||
@@ -121,7 +122,8 @@ async function sendInfo(socket) {
 | 
			
		||||
    socket.emit("info", {
 | 
			
		||||
        version: checkVersion.version,
 | 
			
		||||
        latestVersion: checkVersion.latestVersion,
 | 
			
		||||
        primaryBaseURL: await setting("primaryBaseURL")
 | 
			
		||||
        primaryBaseURL: await setting("primaryBaseURL"),
 | 
			
		||||
        serverTimezone: await server.getTimezone(),
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
const { BeanModel } = require("redbean-node/dist/bean-model");
 | 
			
		||||
const { parseTimeObject, parseTimeFromTimeObject, isoToUTCDateTime, utcToISODateTime } = require("../../src/util");
 | 
			
		||||
const { parseTimeObject, parseTimeFromTimeObject, isoToUTCDateTime, utcToISODateTime, SQL_DATETIME_FORMAT, utcToLocal, localToUTC } = require("../../src/util");
 | 
			
		||||
const { isArray } = require("chart.js/helpers");
 | 
			
		||||
const { timeObjectToUTC, timeObjectToLocal } = require("../util-server");
 | 
			
		||||
 | 
			
		||||
@@ -15,9 +15,9 @@ class Maintenance extends BeanModel {
 | 
			
		||||
 | 
			
		||||
        let dateRange = [];
 | 
			
		||||
        if (this.start_date) {
 | 
			
		||||
            dateRange.push(utcToISODateTime(this.start_date));
 | 
			
		||||
            dateRange.push(utcToLocal(this.start_date));
 | 
			
		||||
            if (this.end_date) {
 | 
			
		||||
                dateRange.push(utcToISODateTime(this.end_date));
 | 
			
		||||
                dateRange.push(utcToLocal(this.end_date));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -92,10 +92,10 @@ class Maintenance extends BeanModel {
 | 
			
		||||
        bean.active = obj.active;
 | 
			
		||||
 | 
			
		||||
        if (obj.dateRange[0]) {
 | 
			
		||||
            bean.start_date = isoToUTCDateTime(obj.dateRange[0]);
 | 
			
		||||
            bean.start_date = localToUTC(obj.dateRange[0]);
 | 
			
		||||
 | 
			
		||||
            if (obj.dateRange[1]) {
 | 
			
		||||
                bean.end_date = isoToUTCDateTime(obj.dateRange[1]);
 | 
			
		||||
                bean.end_date = localToUTC(obj.dateRange[1]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -616,7 +616,7 @@ export default {
 | 
			
		||||
    recurringInterval: "Interval",
 | 
			
		||||
    "Recurring": "Recurring",
 | 
			
		||||
    strategyManual: "Active/Inactive Manually",
 | 
			
		||||
    warningTimezone: "It is using your current Device/PC's timezone.",
 | 
			
		||||
    warningTimezone: "It is using the server's timezone",
 | 
			
		||||
    weekdayShortMon: "Mon",
 | 
			
		||||
    weekdayShortTue: "Tue",
 | 
			
		||||
    weekdayShortWed: "Wed",
 | 
			
		||||
 
 | 
			
		||||
@@ -82,7 +82,7 @@
 | 
			
		||||
 | 
			
		||||
                            <h2 class="mt-5">{{ $t("Date and Time") }}</h2>
 | 
			
		||||
 | 
			
		||||
                            <div>⚠️ {{ $t("warningTimezone") }}</div>
 | 
			
		||||
                            <div>⚠️ {{ $t("warningTimezone") }}: {{ $root.info.serverTimezone }}</div>
 | 
			
		||||
 | 
			
		||||
                            <!-- Strategy -->
 | 
			
		||||
                            <div class="my-3">
 | 
			
		||||
@@ -105,10 +105,11 @@
 | 
			
		||||
                                    <Datepicker
 | 
			
		||||
                                        v-model="maintenance.dateRange"
 | 
			
		||||
                                        :dark="$root.isDark"
 | 
			
		||||
                                        range textInput
 | 
			
		||||
                                        range
 | 
			
		||||
                                        :monthChangeOnScroll="false"
 | 
			
		||||
                                        :minDate="minDate"
 | 
			
		||||
                                        format="yyyy-MM-dd HH:mm"
 | 
			
		||||
                                        modelType="yyyy-MM-dd HH:mm:ss"
 | 
			
		||||
                                    />
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </template>
 | 
			
		||||
@@ -186,7 +187,6 @@
 | 
			
		||||
                                        :dark="$root.isDark"
 | 
			
		||||
                                        timePicker
 | 
			
		||||
                                        disableTimeRangeValidation range
 | 
			
		||||
                                        textInput
 | 
			
		||||
                                    />
 | 
			
		||||
                                </div>
 | 
			
		||||
 | 
			
		||||
@@ -196,7 +196,7 @@
 | 
			
		||||
                                    <Datepicker
 | 
			
		||||
                                        v-model="maintenance.dateRange"
 | 
			
		||||
                                        :dark="$root.isDark"
 | 
			
		||||
                                        range textInput datePicker
 | 
			
		||||
                                        range datePicker
 | 
			
		||||
                                        :monthChangeOnScroll="false"
 | 
			
		||||
                                        :minDate="minDate"
 | 
			
		||||
                                        :enableTimePicker="false"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								src/util.js
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/util.js
									
									
									
									
									
								
							@@ -7,7 +7,7 @@
 | 
			
		||||
// Backend uses the compiled file util.js
 | 
			
		||||
// Frontend uses util.ts
 | 
			
		||||
Object.defineProperty(exports, "__esModule", { value: true });
 | 
			
		||||
exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
 | 
			
		||||
exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
 | 
			
		||||
const dayjs = require("dayjs");
 | 
			
		||||
exports.isDev = process.env.NODE_ENV === "development";
 | 
			
		||||
exports.appName = "Uptime Kuma";
 | 
			
		||||
@@ -19,6 +19,8 @@ exports.STATUS_PAGE_ALL_DOWN = 0;
 | 
			
		||||
exports.STATUS_PAGE_ALL_UP = 1;
 | 
			
		||||
exports.STATUS_PAGE_PARTIAL_DOWN = 2;
 | 
			
		||||
exports.STATUS_PAGE_MAINTENANCE = 3;
 | 
			
		||||
exports.SQL_DATE_FORMAT = "YYYY-MM-DD";
 | 
			
		||||
exports.SQL_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
 | 
			
		||||
/** Flip the status of s */
 | 
			
		||||
function flipStatus(s) {
 | 
			
		||||
    if (s === exports.UP) {
 | 
			
		||||
@@ -351,7 +353,7 @@ function parseTimeFromTimeObject(obj) {
 | 
			
		||||
}
 | 
			
		||||
exports.parseTimeFromTimeObject = parseTimeFromTimeObject;
 | 
			
		||||
function isoToUTCDateTime(input) {
 | 
			
		||||
    return dayjs(input).utc().format("YYYY-MM-DD HH:mm:ss");
 | 
			
		||||
    return dayjs(input).utc().format(exports.SQL_DATETIME_FORMAT);
 | 
			
		||||
}
 | 
			
		||||
exports.isoToUTCDateTime = isoToUTCDateTime;
 | 
			
		||||
/**
 | 
			
		||||
@@ -361,3 +363,15 @@ function utcToISODateTime(input) {
 | 
			
		||||
    return dayjs.utc(input).toISOString();
 | 
			
		||||
}
 | 
			
		||||
exports.utcToISODateTime = utcToISODateTime;
 | 
			
		||||
/**
 | 
			
		||||
/**
 | 
			
		||||
 * For SQL_DATETIME_FORMAT
 | 
			
		||||
 */
 | 
			
		||||
function utcToLocal(input) {
 | 
			
		||||
    return dayjs.utc(input).local().format(exports.SQL_DATETIME_FORMAT);
 | 
			
		||||
}
 | 
			
		||||
exports.utcToLocal = utcToLocal;
 | 
			
		||||
function localToUTC(input) {
 | 
			
		||||
    return dayjs(input).utc().format(exports.SQL_DATETIME_FORMAT);
 | 
			
		||||
}
 | 
			
		||||
exports.localToUTC = localToUTC;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								src/util.ts
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/util.ts
									
									
									
									
									
								
							@@ -23,6 +23,9 @@ export const STATUS_PAGE_ALL_UP = 1;
 | 
			
		||||
export const STATUS_PAGE_PARTIAL_DOWN = 2;
 | 
			
		||||
export const STATUS_PAGE_MAINTENANCE = 3;
 | 
			
		||||
 | 
			
		||||
export const SQL_DATE_FORMAT = "YYYY-MM-DD";
 | 
			
		||||
export const SQL_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
 | 
			
		||||
 | 
			
		||||
/** Flip the status of s */
 | 
			
		||||
export function flipStatus(s: number) {
 | 
			
		||||
    if (s === UP) {
 | 
			
		||||
@@ -396,7 +399,7 @@ export function parseTimeFromTimeObject(obj : any) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export function isoToUTCDateTime(input : string) {
 | 
			
		||||
    return dayjs(input).utc().format("YYYY-MM-DD HH:mm:ss");
 | 
			
		||||
    return dayjs(input).utc().format(SQL_DATETIME_FORMAT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -405,3 +408,15 @@ export function isoToUTCDateTime(input : string) {
 | 
			
		||||
export function utcToISODateTime(input : string) {
 | 
			
		||||
    return dayjs.utc(input).toISOString();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
/**
 | 
			
		||||
 * For SQL_DATETIME_FORMAT
 | 
			
		||||
 */
 | 
			
		||||
export function utcToLocal(input : string) {
 | 
			
		||||
    return dayjs.utc(input).local().format(SQL_DATETIME_FORMAT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function localToUTC(input : string) {
 | 
			
		||||
    return dayjs(input).utc().format(SQL_DATETIME_FORMAT);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user