Help us shape the future of Go! Take the 2026 Go Developer Survey

offpeak

package
v0.40.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 7 Imported by: 0

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

View Source
const (
	MaxWindows  = 8
	MaxRate     = 5.0
	MaxLabelLen = 40
	MaxTZLen    = 64
)

Limits of a schedule.

View Source
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

func ParseClock(s string) (int, bool)

ParseClock reads "HH:MM" (00:00 to 23:59) as minutes since midnight.

Types

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Msg   string `json:"error"`
}

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 Instance

type Instance struct {
	Start, End time.Time
	Rate       float64
}

Instance is one occurrence of a window on a particular night or day, as instants.

type Schedule

type Schedule struct {
	TZ      string   `json:"tz"`
	Windows []Window `json:"windows"`
}

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

func (s Schedule) Instances(from, to time.Time) []Instance

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL