Пример #1
0
//makeTimeConfig converts map of strings to strings (formatted as time) to a TimeConfig struct.
func makeTimeConfig(times map[string]string) (tc TimeConfig, err error) {
	on, err := time.Parse(timeFormat, times["TurnOn"])
	if err != nil {
		return
	}

	off, err := time.Parse(timeFormat, times["TurnOff"])
	if err != nil {
		return
	}

	tc.TurnOn = util.NormalizeTime(on)
	tc.TurnOff = util.NormalizeTime(off)

	return
}
Пример #2
0
func TestNormalizeTime(t *testing.T) {
	t.Parallel()
	testf := func(y, m, d, h, min, s, n int) bool {
		date := time.Date(y, time.Month(m), d, h, min, s, n, time.UTC)
		norm := util.NormalizeTime(date)
		return (norm.Year() == 0) && (norm.Month() == 1) && (norm.Day() == 1) && (norm.Location() == util.Tz)
	}

	err := quick.Check(testf, &conf)
	if err != nil {
		t.Error(err)
	}
}
Пример #3
0
//IsBroadcastingTime tests if it should broadcast on time with timeconfig.
func (tc TimeConfig) IsBroadcastingTime(t time.Time) bool {
	afterOn := util.NormalizeTime(t).After(tc.TurnOn)
	beforeOff := tc.TurnOff.After(util.NormalizeTime(t))
	return afterOn && beforeOff
}