Skip to content

Commit 2f4b9b0

Browse files
author
noah
committed
Add example
1 parent 0fa3cf2 commit 2f4b9b0

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

test/main.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
package main
22

33
import (
4-
"fmt"
4+
"log"
55
"time"
6+
7+
"github.com/gitploy-io/cronexpr"
68
)
79

8-
func main() {
9-
t := time.Date(2021, 6, 0, 23, 59, 59, 0, time.UTC)
10-
fmt.Println(t)
10+
// verifyFreezeWindow verifies the time satisfy being between two cronexpr.
11+
func verifyFreezeWindow(begin, end string, t time.Time) (bool, error) {
12+
b, err := cronexpr.Parse(begin)
13+
if err != nil {
14+
return false, err
15+
}
16+
17+
e, err := cronexpr.Parse(end)
18+
if err != nil {
19+
return false, err
20+
}
21+
22+
if !(t.Before(b.Prev(t)) && t.After(e.Next(t))) {
23+
return false, nil
24+
}
1125

12-
t = time.Date(t.Year(), t.Month(), 0, 23, 59, 59, 0, time.UTC)
13-
fmt.Println(t)
26+
return true, nil
27+
}
28+
29+
func main() {
30+
t := time.Date(2021, 12, 25, 0, 0, 0, 0, time.UTC)
1431

15-
t = time.Date(t.Year(), t.Month(), 0, 23, 59, 59, 0, time.UTC)
16-
fmt.Println(t)
32+
ok, _ := verifyFreezeWindow("* 23 24 DEC *", "* 1 25 DEC *", t)
33+
if !ok {
34+
log.Printf("Blocked to deploy at the midnight of X-mas.")
35+
}
1736
}

0 commit comments

Comments
 (0)