Ad

Replace comparison with two constants for the workday with one Mod operation.

Code
Diff
  • package kumite
    
    import "time"
    
    func CheckWorkHours(dateTime time.Time) bool {
      const (
        WK_HOUR_BEGIN = 8
        WK_HOUR_END = 18
      )
      
      hour := dateTime.Hour()
      wday := dateTime.Weekday()
      
      return wday % 6 != 0 && WK_HOUR_BEGIN <= hour && hour < WK_HOUR_END
    }
    
    • package kumite
    • import "time"
    • func CheckWorkHours(dateTime time.Time) bool {
    • // It's better to have constants for work interval
    • const (
    • WK_HOUR_BEGIN = 8
    • WK_HOUR_END = 18
    • WK_DAY_BEGIN = 1
    • WK_DAY_END = 6
    • )
    • hour := dateTime.Hour()
    • day := dateTime.Weekday()
    • wday := dateTime.Weekday()
    • return WK_DAY_BEGIN <= day && day < WK_DAY_END && WK_HOUR_BEGIN <= hour && hour < WK_HOUR_END
    • return wday % 6 != 0 && WK_HOUR_BEGIN <= hour && hour < WK_HOUR_END
    • }