Fix dayjs issue on frontend (#4881)

pull/4884/head
Louis Lam 5 months ago committed by GitHub
parent a81f949f98
commit 1185b259c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,9 +6,12 @@
// //
// Backend uses the compiled file util.js // Backend uses the compiled file util.js
// Frontend uses util.ts // Frontend uses util.ts
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
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.badgeConstants = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = 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; 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.badgeConstants = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = 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_1 = __importDefault(require("dayjs"));
exports.isDev = process.env.NODE_ENV === "development"; exports.isDev = process.env.NODE_ENV === "development";
exports.appName = "Uptime Kuma"; exports.appName = "Uptime Kuma";
exports.DOWN = 0; exports.DOWN = 0;
@ -129,11 +132,11 @@ class Logger {
module = module.toUpperCase(); module = module.toUpperCase();
level = level.toUpperCase(); level = level.toUpperCase();
let now; let now;
if (dayjs.tz) { if (dayjs_1.default.tz) {
now = dayjs.tz(new Date()).format(); now = dayjs_1.default.tz(new Date()).format();
} }
else { else {
now = dayjs().format(); now = (0, dayjs_1.default)().format();
} }
const formattedMessage = (typeof msg === "string") ? `${now} [${module}] ${level}: ${msg}` : msg; const formattedMessage = (typeof msg === "string") ? `${now} [${module}] ${level}: ${msg}` : msg;
if (level === "INFO") { if (level === "INFO") {
@ -222,7 +225,7 @@ function polyfill() {
exports.polyfill = polyfill; exports.polyfill = polyfill;
class TimeLogger { class TimeLogger {
constructor() { constructor() {
this.startTime = dayjs().valueOf(); this.startTime = (0, dayjs_1.default)().valueOf();
} }
/** /**
* Output time since start of monitor * Output time since start of monitor
@ -230,7 +233,7 @@ class TimeLogger {
*/ */
print(name) { print(name) {
if (exports.isDev && process.env.TIMELOGGER === "1") { if (exports.isDev && process.env.TIMELOGGER === "1") {
console.log(name + ": " + (dayjs().valueOf() - this.startTime) + "ms"); console.log(name + ": " + ((0, dayjs_1.default)().valueOf() - this.startTime) + "ms");
} }
} }
} }
@ -394,21 +397,21 @@ exports.parseTimeFromTimeObject = parseTimeFromTimeObject;
* @returns ISO Date time * @returns ISO Date time
*/ */
function isoToUTCDateTime(input) { function isoToUTCDateTime(input) {
return dayjs(input).utc().format(exports.SQL_DATETIME_FORMAT); return (0, dayjs_1.default)(input).utc().format(exports.SQL_DATETIME_FORMAT);
} }
exports.isoToUTCDateTime = isoToUTCDateTime; exports.isoToUTCDateTime = isoToUTCDateTime;
/** /**
* @param input * @param input
*/ */
function utcToISODateTime(input) { function utcToISODateTime(input) {
return dayjs.utc(input).toISOString(); return dayjs_1.default.utc(input).toISOString();
} }
exports.utcToISODateTime = utcToISODateTime; exports.utcToISODateTime = utcToISODateTime;
/** /**
* For SQL_DATETIME_FORMAT * For SQL_DATETIME_FORMAT
*/ */
function utcToLocal(input, format = exports.SQL_DATETIME_FORMAT) { function utcToLocal(input, format = exports.SQL_DATETIME_FORMAT) {
return dayjs.utc(input).local().format(format); return dayjs_1.default.utc(input).local().format(format);
} }
exports.utcToLocal = utcToLocal; exports.utcToLocal = utcToLocal;
/** /**
@ -418,6 +421,6 @@ exports.utcToLocal = utcToLocal;
* @returns Date in requested format * @returns Date in requested format
*/ */
function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) { function localToUTC(input, format = exports.SQL_DATETIME_FORMAT) {
return dayjs(input).utc().format(format); return (0, dayjs_1.default)(input).utc().format(format);
} }
exports.localToUTC = localToUTC; exports.localToUTC = localToUTC;

@ -6,7 +6,7 @@
// Backend uses the compiled file util.js // Backend uses the compiled file util.js
// Frontend uses util.ts // Frontend uses util.ts
import * as dayjs from "dayjs"; import dayjs from "dayjs";
import * as timezone from "dayjs/plugin/timezone"; import * as timezone from "dayjs/plugin/timezone";
import * as utc from "dayjs/plugin/utc"; import * as utc from "dayjs/plugin/utc";

@ -11,7 +11,8 @@
"removeComments": false, "removeComments": false,
"preserveConstEnums": true, "preserveConstEnums": true,
"sourceMap": false, "sourceMap": false,
"strict": true "strict": true,
"esModuleInterop": true
}, },
"files": [ "files": [
"./src/util.ts" "./src/util.ts"

Loading…
Cancel
Save