Documentation
¶
Overview ¶
Package offpeak is the user's electricity schedule: the times of day (in their own time zone) at which their plan charges a different rate, and the checks that keep a schedule well formed. Rivolt only uses it for estimates; it never contacts a utility and cannot check the numbers.
Index ¶
Constants ¶
const ( MaxWindows = 8 MaxRate = 5.0 MaxLabelLen = 40 MaxTZLen = 64 )
Limits of a schedule.
const ( Weekdays = "weekdays" Weekends = "weekends" All = "all" )
Days of a window: Mon-Fri, Sat-Sun, or every day.
Variables ¶
This section is empty.
Functions ¶
func Normalize ¶
func Normalize(s Schedule) (Schedule, *FieldError)
Normalize checks s and returns it with rates rounded to 4 decimals. An empty schedule (no windows) is valid and clears the schedule.
func ParseClock ¶
ParseClock reads "HH:MM" (00:00 to 23:59) as minutes since midnight.
Types ¶
type FieldError ¶
FieldError is a validation failure with the path of the field at fault ("windows[2].end"), so a form can show it beside the right row.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
type Schedule ¶
Schedule is the user's windows and the IANA zone their times are read in. Hours outside every window are priced at the user's flat home rate.
func (Schedule) Instances ¶
Instances lists every occurrence of the schedule's windows that overlaps [from, to), in the schedule's own zone. Wall-clock times follow the zone's rules: on a spring-forward day a window minute that does not exist is skipped over by the clock, on a fall-back day the repeated hour is part of the window. The schedule must have passed Normalize.
type Window ¶
type Window struct {
Days string `json:"days"`
Start string `json:"start"`
End string `json:"end"`
Rate float64 `json:"rate"`
Label string `json:"label,omitempty"`
}
Window is one stretch of the day at one rate. Start and End are local wall-clock times ("21:00"); End at or before Start crosses midnight into the next day. Rate is in the user's home currency per kWh.