github.com/iDigitalFlame/xmt@v0.5.4/c2/cfg/workhours_no_implant.go (about)

     1  // Copyright (C) 2020 - 2023 iDigitalFlame
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  //
    16  
    17  package cfg
    18  
    19  // Day bitmask constants
    20  const (
    21  	DaySunday uint8 = 1 << iota
    22  	DayMonday
    23  	DayTuesday
    24  	DayWednesday
    25  	DayThursday
    26  	DayFriday
    27  	DaySaturday
    28  	DayEveryday = 0
    29  )
    30  
    31  // String returns the string version of the WorkHours.Day value. This can be
    32  // parsed back into the numerical version.
    33  func (w WorkHours) String() string {
    34  	return dayNumToString(w.Days)
    35  }
    36  func dayNumToString(d uint8) string {
    37  	if d == 0 || d > 126 {
    38  		return "SMTWRFS"
    39  	}
    40  	var (
    41  		b [7]byte
    42  		n int
    43  	)
    44  	if d&DaySunday != 0 {
    45  		b[n] = 'S'
    46  		n++
    47  	}
    48  	if d&DayMonday != 0 {
    49  		b[n] = 'M'
    50  		n++
    51  	}
    52  	if d&DayTuesday != 0 {
    53  		b[n] = 'T'
    54  		n++
    55  	}
    56  	if d&DayWednesday != 0 {
    57  		b[n] = 'W'
    58  		n++
    59  	}
    60  	if d&DayThursday != 0 {
    61  		b[n] = 'R'
    62  		n++
    63  	}
    64  	if d&DayFriday != 0 {
    65  		b[n] = 'F'
    66  		n++
    67  	}
    68  	if d&DaySaturday != 0 {
    69  		b[n] = 'S'
    70  		n++
    71  	}
    72  	return string(b[:n])
    73  }