Change DateTime Range using serverTimezone

pull/1213/head
Louis Lam 2 years ago
parent a36f24d827
commit a577fba848

@ -4,7 +4,8 @@
const { TimeLogger } = require("../src/util"); const { TimeLogger } = require("../src/util");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { UptimeKumaServer } = require("./uptime-kuma-server"); 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 { setting } = require("./util-server");
const checkVersion = require("./check-version"); const checkVersion = require("./check-version");
@ -121,7 +122,8 @@ async function sendInfo(socket) {
socket.emit("info", { socket.emit("info", {
version: checkVersion.version, version: checkVersion.version,
latestVersion: checkVersion.latestVersion, 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 { 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 { isArray } = require("chart.js/helpers");
const { timeObjectToUTC, timeObjectToLocal } = require("../util-server"); const { timeObjectToUTC, timeObjectToLocal } = require("../util-server");
@ -15,9 +15,9 @@ class Maintenance extends BeanModel {
let dateRange = []; let dateRange = [];
if (this.start_date) { if (this.start_date) {
dateRange.push(utcToISODateTime(this.start_date)); dateRange.push(utcToLocal(this.start_date));
if (this.end_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; bean.active = obj.active;
if (obj.dateRange[0]) { if (obj.dateRange[0]) {
bean.start_date = isoToUTCDateTime(obj.dateRange[0]); bean.start_date = localToUTC(obj.dateRange[0]);
if (obj.dateRange[1]) { 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", recurringInterval: "Interval",
"Recurring": "Recurring", "Recurring": "Recurring",
strategyManual: "Active/Inactive Manually", strategyManual: "Active/Inactive Manually",
warningTimezone: "It is using your current Device/PC's timezone.", warningTimezone: "It is using the server's timezone",
weekdayShortMon: "Mon", weekdayShortMon: "Mon",
weekdayShortTue: "Tue", weekdayShortTue: "Tue",
weekdayShortWed: "Wed", weekdayShortWed: "Wed",

@ -82,7 +82,7 @@
<h2 class="mt-5">{{ $t("Date and Time") }}</h2> <h2 class="mt-5">{{ $t("Date and Time") }}</h2>
<div> {{ $t("warningTimezone") }}</div> <div> {{ $t("warningTimezone") }}: {{ $root.info.serverTimezone }}</div>
<!-- Strategy --> <!-- Strategy -->
<div class="my-3"> <div class="my-3">
@ -105,10 +105,11 @@
<Datepicker <Datepicker
v-model="maintenance.dateRange" v-model="maintenance.dateRange"
:dark="$root.isDark" :dark="$root.isDark"
range textInput range
:monthChangeOnScroll="false" :monthChangeOnScroll="false"
:minDate="minDate" :minDate="minDate"
format="yyyy-MM-dd HH:mm" format="yyyy-MM-dd HH:mm"
modelType="yyyy-MM-dd HH:mm:ss"
/> />
</div> </div>
</template> </template>
@ -186,7 +187,6 @@
:dark="$root.isDark" :dark="$root.isDark"
timePicker timePicker
disableTimeRangeValidation range disableTimeRangeValidation range
textInput
/> />
</div> </div>
@ -196,7 +196,7 @@
<Datepicker <Datepicker
v-model="maintenance.dateRange" v-model="maintenance.dateRange"
:dark="$root.isDark" :dark="$root.isDark"
range textInput datePicker range datePicker
:monthChangeOnScroll="false" :monthChangeOnScroll="false"
:minDate="minDate" :minDate="minDate"
:enableTimePicker="false" :enableTimePicker="false"

@ -7,7 +7,7 @@
// Backend uses the compiled file util.js // Backend uses the compiled file util.js
// Frontend uses util.ts // Frontend uses util.ts
Object.defineProperty(exports, "__esModule", { value: true }); 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"); const dayjs = require("dayjs");
exports.isDev = process.env.NODE_ENV === "development"; exports.isDev = process.env.NODE_ENV === "development";
exports.appName = "Uptime Kuma"; exports.appName = "Uptime Kuma";
@ -19,6 +19,8 @@ exports.STATUS_PAGE_ALL_DOWN = 0;
exports.STATUS_PAGE_ALL_UP = 1; exports.STATUS_PAGE_ALL_UP = 1;
exports.STATUS_PAGE_PARTIAL_DOWN = 2; exports.STATUS_PAGE_PARTIAL_DOWN = 2;
exports.STATUS_PAGE_MAINTENANCE = 3; 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 */ /** Flip the status of s */
function flipStatus(s) { function flipStatus(s) {
if (s === exports.UP) { if (s === exports.UP) {
@ -351,7 +353,7 @@ function parseTimeFromTimeObject(obj) {
} }
exports.parseTimeFromTimeObject = parseTimeFromTimeObject; exports.parseTimeFromTimeObject = parseTimeFromTimeObject;
function isoToUTCDateTime(input) { 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; exports.isoToUTCDateTime = isoToUTCDateTime;
/** /**
@ -361,3 +363,15 @@ function utcToISODateTime(input) {
return dayjs.utc(input).toISOString(); return dayjs.utc(input).toISOString();
} }
exports.utcToISODateTime = utcToISODateTime; 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;

@ -23,6 +23,9 @@ export const STATUS_PAGE_ALL_UP = 1;
export const STATUS_PAGE_PARTIAL_DOWN = 2; export const STATUS_PAGE_PARTIAL_DOWN = 2;
export const STATUS_PAGE_MAINTENANCE = 3; 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 */ /** Flip the status of s */
export function flipStatus(s: number) { export function flipStatus(s: number) {
if (s === UP) { if (s === UP) {
@ -396,7 +399,7 @@ export function parseTimeFromTimeObject(obj : any) {
export function isoToUTCDateTime(input : string) { 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) { export function utcToISODateTime(input : string) {
return dayjs.utc(input).toISOString(); 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);
}

Loading…
Cancel
Save