db

package
v0.0.0-...-cc16d5f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2015 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const DateFormat = "1/2/06"

Variables

This section is empty.

Functions

func ParseDate

func ParseDate(date string, location *time.Location) (t time.Time, err error)

func ParseTimeClock

func ParseTimeClock(cc *CalendarConfig) (tc *timeClock, err error)

func ParseTimeOfDay

func ParseTimeOfDay(tod string) (t time.Time, err error)

Types

type Calendar

type Calendar interface {
	RuleAt(t time.Time) (isOn bool, period TimePeriod)
}

func NewCalendar

func NewCalendar(cc *CalendarConfig) (tc Calendar, err error)

type CalendarConfig

type CalendarConfig struct {
	Location       string
	SchoolDayHours TimeOfDayPeriodConfig
	VacationHours  TimeOfDayPeriodConfig
	Holidays       []DateRangeConfig
}

type DB

type DB interface {
	Open() (err error)
	Add(d Device) (err error)
	AddAll(devices []Device) (err error)
	Remove(ip DeviceIP) (err error)
	Find(ip DeviceIP) (device Device, found bool, err error)
	All() (devices []Device, err error)
	SetActiveUntil(ip DeviceIP, activeUntil time.Time) (err error)

	// Modify the active time by the delta, taking into account the baseTime.
	// Typically the baseTIme is "now".
	// activeTime := max(max(activeTime, baseTime) + delta, baseTime)
	ModifyActiveUntil(ip DeviceIP, delta time.Duration, baseTime time.Time) (err error)
	Close() (err error)
}

func NewRAMDB

func NewRAMDB() (d DB)

A RAM-based DB does not persist to disk.

type DatePeriod

type DatePeriod TimePeriod

func ParseDateRange

func ParseDateRange(dr DateRangeConfig, location *time.Location) (dp DatePeriod, err error)

func (DatePeriod) Equal

func (tp DatePeriod) Equal(o DatePeriod) bool

func (DatePeriod) String

func (d DatePeriod) String() string

type DateRangeConfig

type DateRangeConfig struct {
	StartDay string
	// This is inclusive
	EndDay string
}

type Device

type Device struct {
	IP          DeviceIP
	Name        string
	ActiveUntil time.Time
}

func NewDevice

func NewDevice(ip string, name string) Device

type DeviceIP

type DeviceIP net.IP

func GetBlockList

func GetBlockList(db DB, calendar Calendar, atTime time.Time) (blocked []DeviceIP, goodUntil time.Time, err error)

func ParseDeviceIP

func ParseDeviceIP(s string) DeviceIP

func (DeviceIP) Equal

func (d DeviceIP) Equal(x DeviceIP) bool

func (DeviceIP) MarshalText

func (d DeviceIP) MarshalText() ([]byte, error)

func (DeviceIP) String

func (d DeviceIP) String() string

func (*DeviceIP) UnmarshalText

func (d *DeviceIP) UnmarshalText(text []byte) error

type TimeOfDayPeriod

type TimeOfDayPeriod TimePeriod

func ParseTimeOfDayPeriod

func ParseTimeOfDayPeriod(todc TimeOfDayPeriodConfig) (tp TimeOfDayPeriod, err error)

func (TimeOfDayPeriod) Equal

func (tp TimeOfDayPeriod) Equal(o TimeOfDayPeriod) bool

func (TimeOfDayPeriod) String

func (d TimeOfDayPeriod) String() string

type TimeOfDayPeriodConfig

type TimeOfDayPeriodConfig struct {
	StartTime string
	EndTime   string
}

type TimePeriod

type TimePeriod struct {
	Start time.Time
	End   time.Time
}

func (TimePeriod) Equal

func (tp TimePeriod) Equal(o TimePeriod) bool

func (TimePeriod) Includes

func (tp TimePeriod) Includes(u time.Time) bool

Jump to

Keyboard shortcuts

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