master
go 39 lines 1.21 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package timeperiod
4
5 // Config describes a time period definition in YAML/JSON.
6 type Config struct {
7 Name string `yaml:"name" json:"name"`
8 Alias string `yaml:"alias,omitempty" json:"alias"`
9 Rules []RuleConfig `yaml:"rules" json:"rules"`
10 Exclude []string `yaml:"exclude,omitempty" json:"exclude"`
11 }
12
13 // RuleConfig describes one rule entry (weekly, nth_weekday, date).
14 type RuleConfig struct {
15 Type string `yaml:"type" json:"type"`
16 Days []string `yaml:"days,omitempty" json:"days"`
17 Ranges []string `yaml:"ranges" json:"ranges"`
18 Weekday string `yaml:"weekday,omitempty" json:"weekday"`
19 Nth int `yaml:"nth,omitempty" json:"nth"`
20 Dates []string `yaml:"dates,omitempty" json:"dates"`
21 }
22
23 // DefaultPeriodName represents the implicit always-on period.
24 const DefaultPeriodName = "24x7"
25
26 // DefaultPeriodConfig returns the builtin 24x7 schedule.
27 func DefaultPeriodConfig() Config {
28 return Config{
29 Name: DefaultPeriodName,
30 Alias: "Always on",
31 Rules: []RuleConfig{
32 {
33 Type: "weekly",
34 Days: []string{"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"},
35 Ranges: []string{"00:00-24:00"},
36 },
37 },
38 }
39 }