-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_parser_test.go
More file actions
51 lines (42 loc) · 981 Bytes
/
example_parser_test.go
File metadata and controls
51 lines (42 loc) · 981 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package hardloop_test
import (
"fmt"
"log"
"time"
"github.com/robfig/cron/v3"
"github.com/worldline-go/hardloop"
)
func Example_parser() {
schedule := "0 7 * * *"
p := hardloop.Parser{ParseFn: cron.ParseStandard}
s, err := p.Parse2(schedule)
if err != nil {
log.Fatal(err)
}
now := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
fmt.Println("Next 5 times:")
tmpNow := now
for i := 0; i < 5; i++ {
tmpNow = s.Next(tmpNow)
fmt.Println(tmpNow)
}
tmpNow = now
fmt.Println("Prev 5 times:")
for i := 0; i < 5; i++ {
tmpNow = s.Prev(tmpNow)
fmt.Println(tmpNow)
}
// Output:
// Next 5 times:
// 2023-01-01 07:00:00 +0000 UTC
// 2023-01-02 07:00:00 +0000 UTC
// 2023-01-03 07:00:00 +0000 UTC
// 2023-01-04 07:00:00 +0000 UTC
// 2023-01-05 07:00:00 +0000 UTC
// Prev 5 times:
// 2022-12-31 07:00:00 +0000 UTC
// 2022-12-30 07:00:00 +0000 UTC
// 2022-12-29 07:00:00 +0000 UTC
// 2022-12-28 07:00:00 +0000 UTC
// 2022-12-27 07:00:00 +0000 UTC
}