修改时区

This commit is contained in:
jonathang4 2025-06-05 16:40:49 +08:00
parent 615aefbdd5
commit 00c0c14e03
6 changed files with 25 additions and 11 deletions

View File

@ -25,6 +25,7 @@
"crc-32": "^1.2.2", "crc-32": "^1.2.2",
"cron": "^3.1.6", "cron": "^3.1.6",
"date-fns": "^3.3.1", "date-fns": "^3.3.1",
"date-fns-tz": "^3.2.0",
"eventsource-parser": "^1.1.2", "eventsource-parser": "^1.1.2",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",

View File

@ -1,12 +1,14 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import path from 'path'; import path from 'path';
import { format as dateFormat } from 'date-fns'; // import { format as dateFormat } from 'date-fns';
const timeZone = 'Asia/Shanghai'; // Beijing Time
import { formatInTimeZone } from 'date-fns-tz';
const LOG_PATH = path.resolve("./logs/video_task_cache.log"); const LOG_PATH = path.resolve("./logs/video_task_cache.log");
function cacheLog(value: string, color?: string) { function cacheLog(value: string, color?: string) {
try { try {
const head = `[VideoTaskCache][${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")}] `; const head = `[VideoTaskCache][${formatInTimeZone(new Date(),timeZone, "yyyy-MM-dd HH:mm:ss.SSS")}] `;
value = head + value; value = head + value;
// console.log(color ? value[color] : value); // console.log(color ? value[color] : value);
fs.ensureDirSync(path.dirname(LOG_PATH)); fs.ensureDirSync(path.dirname(LOG_PATH));

View File

@ -7,7 +7,9 @@ import path from 'path';
import { spawn } from 'child_process'; import { spawn } from 'child_process';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { format as dateFormat } from 'date-fns'; // import { format as dateFormat } from 'date-fns';
const timeZone = 'Asia/Shanghai'; // Beijing Time
import { formatInTimeZone } from 'date-fns-tz';
import 'colors'; import 'colors';
import { VideoTaskCache } from '@/api/VideoTaskCache.ts'; import { VideoTaskCache } from '@/api/VideoTaskCache.ts';
@ -22,7 +24,7 @@ let currentProcess; //当前运行进程
*/ */
function daemonLog(value, color?: string) { function daemonLog(value, color?: string) {
try { try {
const head = `[daemon][${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")}] `; const head = `[daemon][${formatInTimeZone(new Date(), timeZone, "yyyy-MM-dd HH:mm:ss.SSS")}] `;
value = head + value; value = head + value;
console.log(color ? value[color] : value); console.log(color ? value[color] : value);
fs.ensureDirSync(path.dirname(LOG_PATH)); fs.ensureDirSync(path.dirname(LOG_PATH));

View File

@ -4,7 +4,9 @@ import _util from 'util';
import 'colors'; import 'colors';
import _ from 'lodash'; import _ from 'lodash';
import fs from 'fs-extra'; import fs from 'fs-extra';
import { format as dateFormat } from 'date-fns'; // import { format as dateFormat } from 'date-fns';
const timeZone = 'Asia/Shanghai'; // Beijing Time
import { formatInTimeZone } from 'date-fns-tz';
import config from './config.ts'; import config from './config.ts';
import util from './util.ts'; import util from './util.ts';
@ -89,7 +91,7 @@ class LogText {
} }
toString() { toString() {
return `[${dateFormat(this.time, "yyyy-MM-dd HH:mm:ss.SSS")}][${this.level}][${this.source.name}<${this.source.codeLine},${this.source.codeColumn}>] ${this.text}`; return `[${formatInTimeZone(this.time, timeZone, "yyyy-MM-dd HH:mm:ss.SSS")}][${this.level}][${this.source.name}<${this.source.codeLine},${this.source.codeColumn}>] ${this.text}`;
} }
} }
@ -124,12 +126,12 @@ class Logger {
} }
header() { header() {
this.#writer.writeSync(Buffer.from(`\n\n===================== LOG START ${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")} =====================\n\n`)); this.#writer.writeSync(Buffer.from(`\n\n===================== LOG START ${formatInTimeZone(new Date(), timeZone, "yyyy-MM-dd HH:mm:ss.SSS")} =====================\n\n`));
} }
footer() { footer() {
this.#writer.flush(); //将未写入文件的日志缓存写入 this.#writer.flush(); //将未写入文件的日志缓存写入
this.#writer.writeSync(Buffer.from(`\n\n===================== LOG END ${dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")} =====================\n\n`)); this.#writer.writeSync(Buffer.from(`\n\n===================== LOG END ${formatInTimeZone(new Date(), timeZone, "yyyy-MM-dd HH:mm:ss.SSS")} =====================\n\n`));
} }
success(...params) { success(...params) {

View File

@ -8,7 +8,9 @@ import mime from "mime";
import axios from "axios"; import axios from "axios";
import fs from "fs-extra"; import fs from "fs-extra";
import { v1 as uuid } from "uuid"; import { v1 as uuid } from "uuid";
import { format as dateFormat } from "date-fns"; // import { format as dateFormat } from "date-fns";
const timeZone = 'Asia/Shanghai'; // Beijing Time
import { formatInTimeZone } from 'date-fns-tz';
import CRC32 from "crc-32"; import CRC32 from "crc-32";
import randomstring from "randomstring"; import randomstring from "randomstring";
import _ from "lodash"; import _ from "lodash";
@ -75,7 +77,7 @@ const util = {
}, },
getDateString(format = "yyyy-MM-dd", date = new Date()) { getDateString(format = "yyyy-MM-dd", date = new Date()) {
return dateFormat(date, format); return formatInTimeZone(date, timeZone, format);
}, },
getIPAddressesByIPv4(): string[] { getIPAddressesByIPv4(): string[] {

View File

@ -370,7 +370,12 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.3:
shebang-command "^2.0.0" shebang-command "^2.0.0"
which "^2.0.1" which "^2.0.1"
date-fns@^3.3.1: date-fns-tz@^3.2.0:
version "3.2.0"
resolved "https://registry.npmmirror.com/date-fns-tz/-/date-fns-tz-3.2.0.tgz"
integrity sha512-sg8HqoTEulcbbbVXeg84u5UnlsQa8GS5QXMqjjYIhS4abEVVKIUwe0/l/UhrZdKaL/W5eWZNlbTeEIiOXTcsBQ==
"date-fns@^3.0.0 || ^4.0.0", date-fns@^3.3.1:
version "3.6.0" version "3.6.0"
resolved "https://registry.npmmirror.com/date-fns/-/date-fns-3.6.0.tgz" resolved "https://registry.npmmirror.com/date-fns/-/date-fns-3.6.0.tgz"
integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww== integrity sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==