Skip to content

Commit 25fa8e5

Browse files
committed
Add time.Time and time.Duration types
1 parent 74ec318 commit 25fa8e5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ptr.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ptr
22

3+
import "time"
4+
35
// Int returns pointer to int value
46
func Int(v int) *int {
57
return &v
@@ -89,3 +91,13 @@ func Complex64(v complex64) *complex64 {
8991
func Complex128(v complex128) *complex128 {
9092
return &v
9193
}
94+
95+
// Time returns pointer to time.Time value
96+
func Time(v time.Time) *time.Time {
97+
return &v
98+
}
99+
100+
// Duration returns pointer to time.Duration value
101+
func Duration(v time.Duration) *time.Duration {
102+
return &v
103+
}

ptr_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ptr
33
import (
44
"reflect"
55
"testing"
6+
"time"
67
)
78

89
func equal(t *testing.T, expected, actual interface{}) {
@@ -82,3 +83,11 @@ func TestComplex64(t *testing.T) {
8283
func TestComplex128(t *testing.T) {
8384
equal(t, complex(float64(10.0), float64(100.0)), *Complex128(complex(float64(10.0), float64(100.0))))
8485
}
86+
87+
func TestTime(t *testing.T) {
88+
equal(t, time.Date(2001, 1, 1, 0, 0, 0, 0, time.UTC), *Time(time.Date(2001, 1, 1, 0, 0, 0, 0, time.UTC)))
89+
}
90+
91+
func TestDuration(t *testing.T) {
92+
equal(t, time.Hour, *Duration(time.Hour))
93+
}

0 commit comments

Comments
 (0)