-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathday_of_week.go
48 lines (46 loc) · 1.19 KB
/
day_of_week.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package models
type DayOfWeek int
const (
SUNDAY_DAYOFWEEK DayOfWeek = iota
MONDAY_DAYOFWEEK
TUESDAY_DAYOFWEEK
WEDNESDAY_DAYOFWEEK
THURSDAY_DAYOFWEEK
FRIDAY_DAYOFWEEK
SATURDAY_DAYOFWEEK
)
func (i DayOfWeek) String() string {
return []string{"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"}[i]
}
func ParseDayOfWeek(v string) (any, error) {
result := SUNDAY_DAYOFWEEK
switch v {
case "sunday":
result = SUNDAY_DAYOFWEEK
case "monday":
result = MONDAY_DAYOFWEEK
case "tuesday":
result = TUESDAY_DAYOFWEEK
case "wednesday":
result = WEDNESDAY_DAYOFWEEK
case "thursday":
result = THURSDAY_DAYOFWEEK
case "friday":
result = FRIDAY_DAYOFWEEK
case "saturday":
result = SATURDAY_DAYOFWEEK
default:
return nil, nil
}
return &result, nil
}
func SerializeDayOfWeek(values []DayOfWeek) []string {
result := make([]string, len(values))
for i, v := range values {
result[i] = v.String()
}
return result
}
func (i DayOfWeek) isMultiValue() bool {
return false
}