예제 #1
0
파일: config.go 프로젝트: sellweek/TOGY
//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
파일: util_test.go 프로젝트: sellweek/TOGY
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
파일: time.go 프로젝트: sellweek/TOGY
//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
}