-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_time_test.go
51 lines (38 loc) · 1.2 KB
/
example_time_test.go
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
// Copyright © 2020 Danila Petrunko. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package rdate_test
import (
"fmt"
"time"
"github.com/petrunkodg/rdate"
)
type myBirthdayTimeRule struct{}
func (r *myBirthdayTimeRule) Calculate(pivot time.Time) time.Time {
return time.Date(pivot.Year(), 12, 13, 0, 0, 0, 0, pivot.Location())
}
func (r *myBirthdayTimeRule) Shortcut() rdate.TimeShortcut {
return "my birthday this year"
}
func ExampleTimeFactory_extend() {
pivot := time.Date(2004, 3, 1, 0, 2, 1, 6, time.UTC)
f := rdate.NewTimeFactory()
d, ok := f.Make(pivot, "my birthday this year")
if !ok {
fmt.Println("'my birthday this year' shortcut is not implemented")
}
// 'my birthday this year' shortcut is not implemented
f.Extend([]rdate.TimeRule{&myBirthdayTimeRule{}})
d, ok = f.Make(pivot, "my birthday this year")
if !ok {
fmt.Println("'my birthday this year' shortcut is not implemented")
}
fmt.Println(d)
// 2004-12-13 00:00:00
fmt.Println(d.Time())
// 2004-12-13 00:00:00 +0000 UTC
// Output:
// 'my birthday this year' shortcut is not implemented
// 2004-12-13 00:00:00
// 2004-12-13 00:00:00 +0000 UTC
}