Skip to content

Commit cbd8384

Browse files
committed
support parsing nullable.Time
1 parent 2d2586f commit cbd8384

File tree

3 files changed

+80
-15
lines changed

3 files changed

+80
-15
lines changed

assignstring.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"strings"
99
"time"
1010

11-
fs "github.com/ungerik/go-fs"
11+
"github.com/domonda/go-types/nullable"
12+
"github.com/ungerik/go-fs"
1213
)
1314

1415
func assignString(destVal reflect.Value, sourceStr string) (err error) {
@@ -27,14 +28,24 @@ func assignString(destVal reflect.Value, sourceStr string) (err error) {
2728

2829
case *time.Time:
2930
for _, format := range TimeFormats {
30-
t, err := time.Parse(format, sourceStr)
31+
t, err := time.ParseInLocation(format, sourceStr, time.Local)
3132
if err == nil {
3233
*dest = t
3334
return nil
3435
}
3536
}
3637
return fmt.Errorf("can't parse %q as time.Time using formats %#v", sourceStr, TimeFormats)
3738

39+
case *nullable.Time:
40+
for _, format := range TimeFormats {
41+
t, err := nullable.TimeParseInLocation(format, sourceStr, time.Local)
42+
if err == nil {
43+
*dest = t
44+
return nil
45+
}
46+
}
47+
return fmt.Errorf("can't parse %q as nullable.Time using formats %#v", sourceStr, TimeFormats)
48+
3849
case *time.Duration:
3950
duration, err := time.ParseDuration(sourceStr)
4051
if err != nil {

go.mod

+11-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ module github.com/ungerik/go-command
33
go 1.13
44

55
require (
6-
github.com/domonda/go-types v0.0.0-20200104165438-8a9c3902aa39
7-
github.com/domonda/go-wraperr v0.0.0-20191218095026-c132bf32bd96 // indirect
8-
github.com/domonda/golog v0.0.0-20200104211507-b1ff3be34563
9-
github.com/fatih/color v1.8.0
10-
github.com/gorilla/mux v1.7.3
11-
github.com/guregu/null v3.4.0+incompatible // indirect
12-
github.com/h2non/filetype v1.0.10
13-
github.com/mattn/go-colorable v0.1.4 // indirect
14-
github.com/mattn/go-isatty v0.0.11 // indirect
15-
github.com/stretchr/testify v1.4.0
16-
github.com/ungerik/go-fs v0.0.0-20191127131724-ee9af4c83317
17-
github.com/ungerik/go-httpx v0.0.0-20191022153633-4ee50a95056d
6+
github.com/domonda/go-types v0.0.0-20200508135225-99aa86ad3b7a
7+
github.com/domonda/go-wraperr v0.0.0-20200414143540-485fd6d06d5d // indirect
8+
github.com/domonda/golog v0.0.0-20200504110752-9db73907a050
9+
github.com/fatih/color v1.9.0
10+
github.com/gorilla/mux v1.7.4
11+
github.com/guregu/null v4.0.0+incompatible // indirect
12+
github.com/h2non/filetype v1.0.12
13+
github.com/mattn/go-colorable v0.1.6 // indirect
14+
github.com/stretchr/testify v1.5.1
15+
github.com/ungerik/go-fs v0.0.0-20200425122624-6bc19757f8de
16+
github.com/ungerik/go-httpx v0.0.0-20200430100650-4794cf507bad
1817
github.com/ungerik/go-reflection v0.0.0-20191013094457-172d2e71715f
19-
golang.org/x/sys v0.0.0-20200103143344-a1369afcdac7 // indirect
2018
)

0 commit comments

Comments
 (0)