go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/cron/weekday.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package cron
     9  
    10  import "time"
    11  
    12  var (
    13  	// DaysOfWeek are all the time.Weekday in an array for utility purposes.
    14  	DaysOfWeek = []time.Weekday{
    15  		time.Sunday,
    16  		time.Monday,
    17  		time.Tuesday,
    18  		time.Wednesday,
    19  		time.Thursday,
    20  		time.Friday,
    21  		time.Saturday,
    22  	}
    23  
    24  	// WeekDays are the business time.Weekday in an array.
    25  	WeekDays = []time.Weekday{
    26  		time.Monday,
    27  		time.Tuesday,
    28  		time.Wednesday,
    29  		time.Thursday,
    30  		time.Friday,
    31  	}
    32  
    33  	// WeekendDays are the weekend time.Weekday in an array.
    34  	WeekendDays = []time.Weekday{
    35  		time.Sunday,
    36  		time.Saturday,
    37  	}
    38  
    39  	// Epoch is unix epoch saved for utility purposes.
    40  	Epoch = time.Unix(0, 0)
    41  	// Zero is different than epoch in that it is the "unset" value for a time
    42  	// where Epoch is a valid date. Nominally it is `time.Time{}`.
    43  	Zero = time.Time{}
    44  )
    45  
    46  // NOTE: we have to use shifts here because in their infinite wisdom google didn't make these values powers of two for masking
    47  const (
    48  	// AllDaysMask is a bitmask of all the days of the week.
    49  	AllDaysMask = 1<<uint(time.Sunday) | 1<<uint(time.Monday) | 1<<uint(time.Tuesday) | 1<<uint(time.Wednesday) | 1<<uint(time.Thursday) | 1<<uint(time.Friday) | 1<<uint(time.Saturday)
    50  	// WeekDaysMask is a bitmask of all the weekdays of the week.
    51  	WeekDaysMask = 1<<uint(time.Monday) | 1<<uint(time.Tuesday) | 1<<uint(time.Wednesday) | 1<<uint(time.Thursday) | 1<<uint(time.Friday)
    52  	//WeekendDaysMask is a bitmask of the weekend days of the week.
    53  	WeekendDaysMask = 1<<uint(time.Sunday) | 1<<uint(time.Saturday)
    54  )
    55  
    56  // IsWeekDay returns if the day is a monday->friday.
    57  func IsWeekDay(day time.Weekday) bool {
    58  	return !IsWeekendDay(day)
    59  }
    60  
    61  // IsWeekendDay returns if the day is a monday->friday.
    62  func IsWeekendDay(day time.Weekday) bool {
    63  	return day == time.Saturday || day == time.Sunday
    64  }