Skip to content

Commit

Permalink
Merge pull request #103 from pinpt/less-error
Browse files Browse the repository at this point in the history
remove impossible error from NewDateWithTime⏰
  • Loading branch information
Robin Diddams authored Jul 30, 2020
2 parents ecbd672 + b7a940a commit 78bfd57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions datetime/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ func NewDate(val string) (*Date, error) {
}

// NewDateWithTime returns a new Date object from a time.Time value
func NewDateWithTime(tv time.Time) (*Date, error) {
func NewDateWithTime(tv time.Time) *Date {
_, timezone := tv.Zone()
return &Date{
Epoch: TimeToEpoch(tv),
Rfc3339: tv.Round(time.Millisecond).Format(RFC3339),
Offset: int64(timezone) / 60,
}, nil
}
}

// NewDateFromEpoch returns a new Date object from a epoch time value
Expand Down Expand Up @@ -381,8 +381,7 @@ func ConvertToModel(ts time.Time, dateModel interface{}) {
return
}

// this always returns nil
date, _ := NewDateWithTime(ts)
date := NewDateWithTime(ts)

t := reflect.ValueOf(dateModel).Elem()
t.FieldByName("Rfc3339").Set(reflect.ValueOf(date.Rfc3339))
Expand Down
3 changes: 1 addition & 2 deletions datetime/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func TestDateObject(t *testing.T) {
dt3 := DateFromEpoch(date3.Epoch)
assert.WithinDuration(dt3, time.Now(), time.Second)
assert.Equal(int64(0), date3.Offset) // make sure ISO returns GMT timezone
dt4, err := NewDateWithTime(dt)
assert.NoError(err)
dt4 := NewDateWithTime(dt)
assert.Equal(date1.Epoch, dt4.Epoch)
}

Expand Down

0 comments on commit 78bfd57

Please sign in to comment.