MCPcopy Index your code
hub / github.com/coder/coder / WeekdaysToBitmap

Function WeekdaysToBitmap

codersdk/templates.go:77–100  ·  view source on GitHub ↗

WeekdaysToBitmap converts a list of weekdays to a bitmap in accordance with the schedule package's rules. The 0th bit is Monday, ..., the 6th bit is Sunday. The 7th bit is unused.

(days []string)

Source from the content-addressed store, hash-verified

75// the schedule package's rules. The 0th bit is Monday, ..., the 6th bit is
76// Sunday. The 7th bit is unused.
77func WeekdaysToBitmap(days []string) (uint8, error) {
78 var bitmap uint8
79 for _, day := range days {
80 switch strings.ToLower(day) {
81 case "monday":
82 bitmap |= 1 << 0
83 case "tuesday":
84 bitmap |= 1 << 1
85 case "wednesday":
86 bitmap |= 1 << 2
87 case "thursday":
88 bitmap |= 1 << 3
89 case "friday":
90 bitmap |= 1 << 4
91 case "saturday":
92 bitmap |= 1 << 5
93 case "sunday":
94 bitmap |= 1 << 6
95 default:
96 return 0, xerrors.Errorf("invalid weekday %q", day)
97 }
98 }
99 return bitmap, nil
100}
101
102// BitmapToWeekdays converts a bitmap to a list of weekdays in accordance with
103// the schedule package's rules (see above).

Callers 3

Calls 1

ErrorfMethod · 0.45

Tested by 1