MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / timeRange

Function timeRange

jsext/dateutil.go:219–248  ·  view source on GitHub ↗
(gmt bool, args ...int)

Source from the content-addressed store, hash-verified

217}
218
219func timeRange(gmt bool, args ...int) bool {
220 now := time.Now()
221 if gmt {
222 now = now.UTC()
223 }
224 curHour := now.Hour()
225 curMin := now.Minute()
226 curSec := now.Second()
227 switch len(args) {
228 case 1:
229 return curHour == args[0]
230 case 2:
231 return curHour >= args[0] && curHour <= args[1]
232 case 4:
233 h1, m1 := args[0], args[1]
234 h2, m2 := args[2], args[3]
235 curTotalMin := (curHour * 60) + curMin
236 startTotalMin := (h1 * 60) + m1
237 endTotalMin := (h2 * 60) + m2
238 return curTotalMin >= startTotalMin && curTotalMin <= endTotalMin
239 case 6:
240 h1, m1, s1 := args[0], args[1], args[2]
241 h2, m2, s2 := args[3], args[4], args[5]
242 curTotalSec := (curHour * 3600) + (curMin * 60) + curSec
243 startTotalSec := (h1 * 3600) + (m1 * 60) + s1
244 endTotalSec := (h2 * 3600) + (m2 * 60) + s2
245 return curTotalSec >= startTotalSec && curTotalSec <= endTotalSec
246 }
247 return false
248}
249
250func AddTimeRange(vm *goja.Runtime) error {
251 return vm.GlobalObject().Set("timeRange", func(call goja.FunctionCall) goja.Value {

Callers 1

AddTimeRangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected