Skip to content

Commit

Permalink
chore(civil): refactor methods to use consistent receiver names (#6089)
Browse files Browse the repository at this point in the history
refs: #5703
  • Loading branch information
quartzmo authored May 24, 2022
1 parent c626d89 commit b01df2e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
56 changes: 28 additions & 28 deletions civil/civil.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ func (d Date) DaysSince(s Date) (days int) {
return int(deltaUnix / 86400)
}

// Before reports whether d1 occurs before d2.
func (d1 Date) Before(d2 Date) bool {
if d1.Year != d2.Year {
return d1.Year < d2.Year
// Before reports whether d occurs before d2.
func (d Date) Before(d2 Date) bool {
if d.Year != d2.Year {
return d.Year < d2.Year
}
if d1.Month != d2.Month {
return d1.Month < d2.Month
if d.Month != d2.Month {
return d.Month < d2.Month
}
return d1.Day < d2.Day
return d.Day < d2.Day
}

// After reports whether d1 occurs after d2.
func (d1 Date) After(d2 Date) bool {
return d2.Before(d1)
// After reports whether d occurs after d2.
func (d Date) After(d2 Date) bool {
return d2.Before(d)
}

// IsZero reports whether date fields are set to their default value.
Expand Down Expand Up @@ -185,24 +185,24 @@ func (t Time) IsZero() bool {
return (t.Hour == 0) && (t.Minute == 0) && (t.Second == 0) && (t.Nanosecond == 0)
}

// Before reports whether t1 occurs before t2.
func (t1 Time) Before(t2 Time) bool {
if t1.Hour != t2.Hour {
return t1.Hour < t2.Hour
// Before reports whether t occurs before t2.
func (t Time) Before(t2 Time) bool {
if t.Hour != t2.Hour {
return t.Hour < t2.Hour
}
if t1.Minute != t2.Minute {
return t1.Minute < t2.Minute
if t.Minute != t2.Minute {
return t.Minute < t2.Minute
}
if t1.Second != t2.Second {
return t1.Second < t2.Second
if t.Second != t2.Second {
return t.Second < t2.Second
}

return t1.Nanosecond < t2.Nanosecond
return t.Nanosecond < t2.Nanosecond
}

// After reports whether t1 occurs after t2.
func (t1 Time) After(t2 Time) bool {
return t2.Before(t1)
// After reports whether t occurs after t2.
func (t Time) After(t2 Time) bool {
return t2.Before(t)
}

// MarshalText implements the encoding.TextMarshaler interface.
Expand Down Expand Up @@ -282,14 +282,14 @@ func (dt DateTime) In(loc *time.Location) time.Time {
return time.Date(dt.Date.Year, dt.Date.Month, dt.Date.Day, dt.Time.Hour, dt.Time.Minute, dt.Time.Second, dt.Time.Nanosecond, loc)
}

// Before reports whether dt1 occurs before dt2.
func (dt1 DateTime) Before(dt2 DateTime) bool {
return dt1.In(time.UTC).Before(dt2.In(time.UTC))
// Before reports whether dt occurs before dt2.
func (dt DateTime) Before(dt2 DateTime) bool {
return dt.In(time.UTC).Before(dt2.In(time.UTC))
}

// After reports whether dt1 occurs after dt2.
func (dt1 DateTime) After(dt2 DateTime) bool {
return dt2.Before(dt1)
// After reports whether dt occurs after dt2.
func (dt DateTime) After(dt2 DateTime) bool {
return dt2.Before(dt)
}

// IsZero reports whether datetime fields are set to their default value.
Expand Down
4 changes: 3 additions & 1 deletion civil/civil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ func TestTimeBefore(t *testing.T) {
{Time{12, 20, 0, 0}, Time{12, 30, 0, 0}, true},
{Time{12, 20, 10, 0}, Time{12, 20, 20, 0}, true},
{Time{12, 20, 10, 5}, Time{12, 20, 10, 10}, true},
{Time{12, 20, 10, 5}, Time{12, 20, 10, 5}, false},
} {
if got := test.t1.Before(test.t2); got != test.want {
t.Errorf("%v.Before(%v): got %t, want %t", test.t1, test.t2, got, test.want)
Expand All @@ -321,9 +322,10 @@ func TestTimeAfter(t *testing.T) {
{Time{12, 20, 0, 0}, Time{12, 30, 0, 0}, false},
{Time{12, 20, 10, 0}, Time{12, 20, 20, 0}, false},
{Time{12, 20, 10, 5}, Time{12, 20, 10, 10}, false},
{Time{12, 20, 10, 5}, Time{12, 20, 10, 5}, false},
} {
if got := test.t1.After(test.t2); got != test.want {
t.Errorf("%v.Before(%v): got %t, want %t", test.t1, test.t2, got, test.want)
t.Errorf("%v.After(%v): got %t, want %t", test.t1, test.t2, got, test.want)
}
}
}
Expand Down

0 comments on commit b01df2e

Please sign in to comment.