From 9cc1c2a0bfc63922749e1ff4278d3a9805afe336 Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 20 Jan 2025 12:51:22 +0800 Subject: [PATCH] scheduler log --- lib/db/getSiteData.js | 63 +++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/lib/db/getSiteData.js b/lib/db/getSiteData.js index 53fbd724..cda6c3ee 100755 --- a/lib/db/getSiteData.js +++ b/lib/db/getSiteData.js @@ -356,12 +356,33 @@ function handleDataBeforeReturn(db) { // 新特性,判断文章的发布和下架时间,如果不在有效期内则进行下架处理 const publish = isInRange(p.title, p.date) if (!publish) { + const currentTimestamp = Date.now() + const startTimestamp = getTimestamp( + p.date.start_date, + p.date.start_time, + p.date.time_zone + ) + const endTimestamp = getTimestamp( + p.date.end_date, + p.date.end_time, + p.date.time_zone + ) + console.log( + '[定时任务] 隐藏--> 文章:', + p.title, + '当前时间戳:', + currentTimestamp, + '目标时间戳:', + startTimestamp, + '-', + endTimestamp + ) console.log( '[定时发布] 隐藏--> 文章:', p.title, '当前时间:', - Date.now(), - '目标', + new Date(), + '目标时间:', p.date ) // 隐藏 @@ -651,47 +672,31 @@ function isInRange(title, date = {}) { // 获取当前时间的时间戳(基于目标时区) const currentTimestamp = Date.now() - // 辅助函数:生成指定日期时间的时间戳(基于目标时区) - function getTimestamp(date, time) { - if (!date) return null - const dateTimeString = `${date}T${time}:00` // 拼接日期时间 - return new Date( - new Date(dateTimeString).toLocaleString('en-US', { timeZone: time_zone }) - ).getTime() - } - // 获取开始和结束时间的时间戳 - const startTimestamp = getTimestamp(start_date, start_time) - const endTimestamp = getTimestamp(end_date, end_time) + const startTimestamp = getTimestamp(start_date, start_time, time_zone) + const endTimestamp = getTimestamp(end_date, end_time, time_zone) // 判断是否在范围内 if (startTimestamp && currentTimestamp < startTimestamp) { - console.log( - '[定时发布] 未到发布时间:', - title, - '指定时间:', - new Date(startTimestamp), - '当前时间:', - new Date(currentTimestamp) - ) return false } if (endTimestamp && currentTimestamp > endTimestamp) { - console.log( - '[定时发布] 超过下架时间:', - title, - '指定时间:', - new Date(endTimestamp), - '当前时间:', - new Date(currentTimestamp) - ) return false } return true } +// 辅助函数:生成指定日期时间的时间戳(基于目标时区) +function getTimestamp(date, time, time_zone) { + if (!date) return null + const dateTimeString = `${date}T${time}:00` // 拼接日期时间 + return new Date( + new Date(dateTimeString).toLocaleString('en-US', { timeZone: time_zone }) + ).getTime() +} + /** * 获取导航用的精减文章列表 * gitbook主题用到,只保留文章的标题分类标签分类信息,精减掉摘要密码日期等数据