-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Description
There are currently 3 methods to compare time.Time objects: Before(), Equal() and After(). These are analogous to <, == and >. But the equivalents of <= and >= are missing. I suggest adding BeforeEqual() and AfterEqual() to complete this.
I am fully aware that these new methods are not strictly needed: t.BeforeEqual(u) could be written as either t.Before(u) || t.Equal(u) or !t.After(u) or t.Sub(u) <= 0. However, those three are less readable than a simple and obvious t.BeforeEqual(u). I have written code like
for day := begin; /* day <= end */ !day.After(end); day = day.Add(24 * time.Hour) {
where I felt that the comment was needed to clarify the intent.
Implementation of the proposed methods is trivial.
rogpeppe, ChrisHines, svengreb, 4ad, rafaelvanoni and 3 moreseankhliao, jwoloch, slrz, mpx, martin-sucha and 4 more