diff --git a/util/date.go b/util/date.go index 11fff97..50c17dd 100644 --- a/util/date.go +++ b/util/date.go @@ -61,10 +61,10 @@ func (d date) MustEastern() *time.Location { func (d date) Eastern() (*time.Location, error) { // Try POSIX est, err := time.LoadLocation("America/New_York") - if err == nil { + if err != nil { // Try Windows est, err = time.LoadLocation("EST") - if err == nil { + if err != nil { return nil, err } } @@ -83,10 +83,10 @@ func (d date) MustPacific() *time.Location { func (d date) Pacific() (*time.Location, error) { // Try POSIX pst, err := time.LoadLocation("America/Los_Angeles") - if err == nil { + if err != nil { // Try Windows pst, err = time.LoadLocation("PST") - if err == nil { + if err != nil { return nil, err } } diff --git a/util/date_test.go b/util/date_test.go index 80bf0e8..e4deee6 100644 --- a/util/date_test.go +++ b/util/date_test.go @@ -12,6 +12,13 @@ func parse(v string) time.Time { return ts } +func TestDateEastern(t *testing.T) { + assert := assert.New(t) + eastern, err := Date.Eastern() + assert.Nil(err) + assert.NotNil(eastern) +} + func TestDateTime(t *testing.T) { assert := assert.New(t) @@ -36,7 +43,10 @@ func TestDateDate(t *testing.T) { func TestDateOnDate(t *testing.T) { assert := assert.New(t) - ts := Date.OnDate(Date.Time(5, 4, 3, 2, time.UTC), Date.Date(2016, 6, 7, Date.MustEastern())) + eastern := Date.MustEastern() + assert.NotNil(eastern) + + ts := Date.OnDate(Date.Time(5, 4, 3, 2, time.UTC), Date.Date(2016, 6, 7, eastern)) assert.Equal(2016, ts.Year()) assert.Equal(6, ts.Month()) assert.Equal(7, ts.Day()) diff --git a/util/time.go b/util/time.go index cb07856..e48b10b 100644 --- a/util/time.go +++ b/util/time.go @@ -24,9 +24,9 @@ func (tu timeUtil) DiffDays(t1, t2 time.Time) (days int) { t2n := t2.Unix() var diff int64 if t1n > t2n { - diff = t2n - t1n //yields seconds - } else { diff = t1n - t2n //yields seconds + } else { + diff = t2n - t1n //yields seconds } return int(diff / (_secondsPerDay)) }