github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/internal/schedule/day_time.go (about) 1 package schedule 2 3 // DayTime is a time definition that is agnostic of concrete dates and is only 4 // concerned about hours and minutes. This can be used to define a point in 5 // time that applies to any day of the week. 6 type DayTime struct { 7 Hour int `json:"hour"` 8 Minute int `json:"minute"` 9 } 10 11 // NewDayTime create a new DayTime from an hour and minute. 12 func NewDayTime(hour, minute int) DayTime { 13 return DayTime{hour, minute} 14 } 15 16 // Equal returns true if t is equal to other. 17 func (t DayTime) Equal(other DayTime) bool { 18 return t.Hour == other.Hour && t.Minute == other.Minute 19 } 20 21 // Before returns true if t is before other. 22 func (t DayTime) Before(other DayTime) bool { 23 if t.Hour < other.Hour { 24 return true 25 } 26 27 if t.Hour > other.Hour { 28 return false 29 } 30 31 return t.Minute < other.Minute 32 } 33 34 // After returns true if t is after other. 35 func (t DayTime) After(other DayTime) bool { 36 return !t.Equal(other) && !t.Before(other) 37 } 38 39 // Between returns true if t is between start and end or equal to start. 40 func (t DayTime) Between(start, end DayTime) bool { 41 return t.Equal(start) || (t.After(start) && t.Before(end)) 42 }