generated from tailored/router-db-template
update time fix
This commit is contained in:
54
src/task/utils/time.ts
Normal file
54
src/task/utils/time.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user