-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yuannnh
committed
Feb 6, 2020
1 parent
550d4db
commit e4b8f1b
Showing
2 changed files
with
57 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 目前的时间格式为 hh:mm 的 String, 该方法将其转化为当天的该时间 | ||
export const getTimeFromTimeStr = (timeStr:string) => { | ||
const [hours, minutes] = timeStr.split(':').map(parseInt) | ||
const time = new Date(); | ||
if(hours){ | ||
time.setHours(hours); | ||
} | ||
if(minutes) { | ||
time.setMinutes(minutes) | ||
} | ||
return time; | ||
} | ||
|
||
// 计算当前时间是否介于起始与结束算出时间内 | ||
export const getIsLive = (startTimeStr:string, endTimeStr:string) => { | ||
const now = new Date().getTime(); | ||
const startTime = getTimeFromTimeStr(startTimeStr).getTime(); | ||
const endTime = getTimeFromTimeStr(endTimeStr).getTime(); | ||
return now > startTime && now < endTime; | ||
} | ||
|
||
|