You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From commit, I think we should be using an enum or const for the return type of time.Compare instead of hardcoded values. It makes the code easier to understand and maintain. This can be seen below:
// src/time/time.gopackage time
const (
Same=0Past=+1Furue=-1
)
// ...
seankhliao
changed the title
time: add time.Same, time.Past and time.Future const or enum for time.Compare
proposal: time: add time.Same, time.Past and time.Future const or enum for time.Compare
Dec 8, 2022
The mnemonic I use to remember Compare like operations is that:
t1.Compare(t2) <0// is equivalent to t1 < t2t1.Compare(t2) >0// is equivalent to t1 > t2
Essentially, you replace the Compare with the < or > operator that is just to the right of it.
Similarly:
t1.Compare(t2) <=0// is equivalent to t1 <= t2t1.Compare(t2) >=0// is equivalent to t1 >= t2t1.Compare(t2) ==0// is equivalent to t1 == t2
Oh, I see. I think the current way matches the semantics of bytes.Compare, subtle.ConstantTimeCompare, netip.Addr.Compare so this proposal can be closed.
From commit, I think we should be using an enum or const for the return type of
time.Compare
instead of hardcoded values. It makes the code easier to understand and maintain. This can be seen below:Example code:
The text was updated successfully, but these errors were encountered: