mirror of
https://github.com/vastxie/99AI.git
synced 2025-11-12 11:43:42 +08:00
NineAI 2.4.2
This commit is contained in:
43
dist/common/utils/date.js
vendored
Normal file
43
dist/common/utils/date.js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isExpired = exports.formatCreateOrUpdateDate = exports.formatDate = void 0;
|
||||
const dayjs = require("dayjs");
|
||||
require("dayjs/locale/zh-cn");
|
||||
const a = require("dayjs/plugin/utc");
|
||||
const b = require("dayjs/plugin/timezone");
|
||||
dayjs.locale('zh-cn');
|
||||
dayjs.extend(a);
|
||||
dayjs.extend(b);
|
||||
dayjs.tz.setDefault('Asia/Shanghai');
|
||||
function formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(date).format(format);
|
||||
}
|
||||
exports.formatDate = formatDate;
|
||||
function formatCreateOrUpdateDate(input, format = 'YYYY-MM-DD HH:mm:ss') {
|
||||
if (Array.isArray(input)) {
|
||||
return input.map((t) => {
|
||||
t.createdAt = (t === null || t === void 0 ? void 0 : t.createdAt) ? dayjs(t.createdAt).format(format) : dayjs().format(format);
|
||||
t.updatedAt = (t === null || t === void 0 ? void 0 : t.updatedAt) ? dayjs(t.updatedAt).format(format) : dayjs().format(format);
|
||||
return t;
|
||||
});
|
||||
}
|
||||
else {
|
||||
let obj = {};
|
||||
try {
|
||||
obj = JSON.parse(JSON.stringify(input));
|
||||
}
|
||||
catch (error) {
|
||||
}
|
||||
(obj === null || obj === void 0 ? void 0 : obj.createdAt) && (obj.createdAt = dayjs(obj.createdAt).format(format));
|
||||
(obj === null || obj === void 0 ? void 0 : obj.updatedAt) && (obj.updatedAt = dayjs(obj.updatedAt).format(format));
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
exports.formatCreateOrUpdateDate = formatCreateOrUpdateDate;
|
||||
function isExpired(createdAt, days) {
|
||||
const expireDate = new Date(createdAt.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
const now = new Date();
|
||||
return now > expireDate;
|
||||
}
|
||||
exports.isExpired = isExpired;
|
||||
exports.default = dayjs;
|
||||
Reference in New Issue
Block a user