-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseTargetTime.js
More file actions
27 lines (24 loc) · 889 Bytes
/
parseTargetTime.js
File metadata and controls
27 lines (24 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function parseTargetTime(target) {
// parse target time from the target string
let targetTime = new Date()
if (target.includes("m")) {
const minutes = parseInt(target)
targetTime.setMinutes(targetTime.getMinutes() + minutes)
} else if (target.includes("s")) {
const seconds = parseInt(target)
targetTime.setSeconds(targetTime.getSeconds() + seconds)
} else if (target.includes(":")) {
const [hours, minutes] = target.split(":")
targetTime.setHours(parseInt(hours))
targetTime.setMinutes(parseInt(minutes))
} else {
console.error("Invalid target time")
console.error("Try 'tertim --help' for more information.")
process.exit(-1)
}
if (targetTime < new Date()) {
targetTime.setDate(targetTime.getDate() + 1)
}
return targetTime
}
export default parseTargetTime