add comparison helpers
This commit is contained in:
@@ -54,6 +54,38 @@ func (t ClockTime) Time() time.Time {
|
||||
return time.Date(1970, 1, 1, t.Hour, t.Minute, t.Second, 0, time.UTC)
|
||||
}
|
||||
|
||||
// IsZero checks if the ClockTime is zero (00:00:00) or nil.
|
||||
func (t *ClockTime) IsZero() bool {
|
||||
return t == nil || (t.Hour == 0 && t.Minute == 0 && t.Second == 0)
|
||||
}
|
||||
|
||||
// Equal checks if two ClockTime instances are equal.
|
||||
func (t ClockTime) Equal(other ClockTime) bool {
|
||||
return t.Hour == other.Hour && t.Minute == other.Minute && t.Second == other.Second
|
||||
}
|
||||
|
||||
// Before checks if the ClockTime is before another ClockTime.
|
||||
func (t ClockTime) Before(other ClockTime) bool {
|
||||
if t.Hour != other.Hour {
|
||||
return t.Hour < other.Hour
|
||||
}
|
||||
if t.Minute != other.Minute {
|
||||
return t.Minute < other.Minute
|
||||
}
|
||||
return t.Second < other.Second
|
||||
}
|
||||
|
||||
// After checks if the ClockTime is after another ClockTime.
|
||||
func (t ClockTime) After(other ClockTime) bool {
|
||||
if t.Hour != other.Hour {
|
||||
return t.Hour > other.Hour
|
||||
}
|
||||
if t.Minute != other.Minute {
|
||||
return t.Minute > other.Minute
|
||||
}
|
||||
return t.Second > other.Second
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface for ClockTime.
|
||||
func (t ClockTime) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
|
||||
Reference in New Issue
Block a user