update time fix

This commit is contained in:
2025-06-22 19:41:01 +08:00
parent 7bc9a06b7c
commit e982ddb001
3 changed files with 71 additions and 5 deletions

54
src/task/utils/time.ts Normal file
View File

@@ -0,0 +1,54 @@
import dayjs from 'dayjs';
/**
* 根据当前时间返回对应的时间段
* 返回的时间段是毫秒数
* 例如03:01 - 09:00 返回 120000 (120秒)
* 如果当前时间不在任何时间段内返回0
* @returns
*/
export const getTimeDuration = () => {
// 根据时间返回,返回需要
const timeRangeList = [
{
start: '03:01',
end: '09:00',
duration: 240 * 1000, // 240s
},
{
start: '09:01',
end: '12:00',
duration: 60 * 1000, // 60s
},
{
start: '12:01',
end: '14:00',
duration: 20 * 1000, // 20s
},
{
start: '14:01',
end: '18:00',
duration: 120 * 1000, // 120s
},
{
start: '18:01',
end: '23:59',
duration: 10 * 1000, // 10s
},
{
start: '00:01',
end: '03:00',
duration: 20 * 1000, // 20s
},
];
const currentTime = Date.now();
const currentHour = dayjs(currentTime).format('HH:mm');
for (const range of timeRangeList) {
if (currentHour >= range.start && currentHour <= range.end) {
return range.duration;
}
}
// 如果没有匹配到默认返回0
return 0;
};