Skip to content

Commit

Permalink
read time values from db correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Aug 6, 2021
1 parent 584f7cd commit 0769800
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/persistence/stringtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package persistence
import "time"

type StringTime struct {
Time time.Time
Time time.Time
Valid bool
}

// this seems to be the format that we are using!
Expand All @@ -18,14 +19,17 @@ func (s *StringTime) Scan(value interface{}) error {
switch v := value.(type) {
case *time.Time:
s.Time = *v
break
s.Valid = true
case time.Time:
s.Time = v
s.Valid = true
case string:
t, err := time.Parse(formatString, v)
if err != nil {
return err
}
s.Time = t
break
s.Valid = true
}

return nil
Expand All @@ -47,15 +51,16 @@ func (s *NullStringTime) Scan(value interface{}) error {
case *time.Time:
s.Time = *v
s.Valid = true
break
case time.Time:
s.Time = v
s.Valid = true
case string:
t, err := time.Parse(formatString, v)
if err != nil {
return err
}
s.Time = t
s.Valid = true
break
}

return nil
Expand Down

0 comments on commit 0769800

Please sign in to comment.