|
@@ -1689,37 +1689,50 @@ module.exports = {
|
|
|
return str;
|
|
|
},
|
|
|
calculateNextSendTime(startTime, intervalHours = 6, quietStart = 0, quietEnd = 8) {
|
|
|
- function parseTime(timeStr, day = 0) {
|
|
|
+ function parseTime(stime, timeStr, day = 0) {
|
|
|
const [hours, minutes] = timeStr.split(':').map(Number);
|
|
|
const date = new Date();
|
|
|
- date.setDate(date.getDate() + day);
|
|
|
+ date.setDate(stime.getDate() + day);
|
|
|
date.setHours(hours, minutes, 0, 0); // Set hours and minutes, reset seconds and milliseconds
|
|
|
return date;
|
|
|
}
|
|
|
+ function calculateHoursBetween(start, end) {
|
|
|
+ // 将时间字符串转换为 Date 对象
|
|
|
+ const startTime = new Date(`2000-01-01T${start}`);
|
|
|
+ const endTime = new Date(`2000-01-01T${end}`);
|
|
|
+ // 检查是否跨越了当前日期和隔天日期
|
|
|
+ if (endTime < startTime) {
|
|
|
+ endTime.setDate(endTime.getDate() + 1); // 将结束时间调整到隔天
|
|
|
+ }
|
|
|
+ // 计算两个时间之间的毫秒数差距
|
|
|
+ const timeDifference = endTime - startTime;
|
|
|
+ // 将毫秒数转换为小时并返回
|
|
|
+ const hours = timeDifference / (1000 * 60 * 60);
|
|
|
+ return 24 - hours;
|
|
|
+ }
|
|
|
// let startDateTime = parseTime(startTime);
|
|
|
let startDateTime = startTime;
|
|
|
let endDateTime = new Date(startDateTime.getTime() + intervalHours * 60 * 60 * 1000);
|
|
|
if (quietStart && quietEnd) {
|
|
|
quietStart = (quietStart < 10 ? '0' + quietStart : quietStart) + ':00';
|
|
|
quietEnd = (quietEnd < 10 ? '0' + quietEnd : quietEnd) + ':00';
|
|
|
- let quietStartDateTime = parseTime(quietStart);
|
|
|
- let quietEndDateTime = parseTime(quietEnd);
|
|
|
+ let quietStartDateTime = parseTime(startDateTime, quietStart);
|
|
|
+ let quietEndDateTime = parseTime(startDateTime, quietEnd);
|
|
|
if (quietEndDateTime <= quietStartDateTime) {
|
|
|
quietEndDateTime.setDate(quietEndDateTime.getDate() + 1);
|
|
|
}
|
|
|
// 判断非屏蔽时间内是否大于间隔时间,大于则要再隔天发送
|
|
|
- const hours = this.calculateHoursBetween(quietStart, quietEnd);
|
|
|
+ const hours = calculateHoursBetween(quietStart, quietEnd);
|
|
|
if (hours < intervalHours) {
|
|
|
// 除法算出差的天数
|
|
|
const days = Math.floor(intervalHours / hours);
|
|
|
- quietStartDateTime = parseTime(quietStart, days);
|
|
|
- quietEndDateTime = parseTime(quietEnd, days);
|
|
|
+ quietStartDateTime = parseTime(startDateTime, quietStart, days);
|
|
|
+ quietEndDateTime = parseTime(startDateTime, quietEnd, days);
|
|
|
intervalHours %= hours;
|
|
|
startDateTime.setDate(startDateTime.getDate() + days);
|
|
|
} else if (startDateTime >= quietEndDateTime) {
|
|
|
- quietStartDateTime = parseTime(quietStart, 1);
|
|
|
+ quietStartDateTime = parseTime(startDateTime, quietStart, 1);
|
|
|
}
|
|
|
-
|
|
|
if (quietEndDateTime <= quietStartDateTime) {
|
|
|
quietEndDateTime.setDate(quietEndDateTime.getDate() + 1);
|
|
|
}
|
|
@@ -1737,18 +1750,4 @@ module.exports = {
|
|
|
// endDateTime.getMinutes().toString().padStart(2, '0');
|
|
|
return endDateTime;
|
|
|
},
|
|
|
- calculateHoursBetween(start, end) {
|
|
|
- // 将时间字符串转换为 Date 对象
|
|
|
- const startTime = new Date(`2000-01-01T${start}`);
|
|
|
- const endTime = new Date(`2000-01-01T${end}`);
|
|
|
- // 检查是否跨越了当前日期和隔天日期
|
|
|
- if (endTime < startTime) {
|
|
|
- endTime.setDate(endTime.getDate() + 1); // 将结束时间调整到隔天
|
|
|
- }
|
|
|
- // 计算两个时间之间的毫秒数差距
|
|
|
- const timeDifference = endTime - startTime;
|
|
|
- // 将毫秒数转换为小时并返回
|
|
|
- const hours = timeDifference / (1000 * 60 * 60);
|
|
|
- return 24 - hours;
|
|
|
- },
|
|
|
};
|