Exemple #1
0
func joinCentral(c centralConfig, conf *Config) (err error) {
	conf.StandardTimeSettings, err = makeTimeConfig(c.StandardTimeSettings)
	conf.OverrideDays = make(map[int64]TimeConfig)
	if err != nil {
		return
	}
	for k, v := range c.OverrideDays {
		var (
			key int64
			t   time.Time
		)
		t, err = time.Parse(dateFormat, k)
		if err != nil {
			return
		}
		key = util.NormalizeDate(t).Unix()

		conf.OverrideDays[key], err = makeTimeConfig(v)
		if err != nil {
			return
		}
	}

	conf.UpdateInterval, err = time.ParseDuration(strconv.Itoa(c.UpdateInterval) + "s")

	conf.Weekends = c.Weekends
	conf.OverrideOn = c.OverrideOn
	conf.OverrideOff = c.OverrideOff
	conf.Timestamp = c.Timestamp
	return
}
Exemple #2
0
//BroadcastingTime tests if according to the config there should be a broadcast on specified time.
func (c Config) BroadcastingTime(t time.Time) bool {
	if c.OverrideOn {
		return true
	}
	if c.OverrideOff {
		return false
	}
	if c.IsOverriddenDay(t) {
		return c.OverrideDays[util.NormalizeDate(t).Unix()].IsBroadcastingTime(t)
	}
	if c.Weekends {
		return c.StandardTimeSettings.IsBroadcastingTime(t)
	}

	return !isWeekend(t) && c.StandardTimeSettings.IsBroadcastingTime(t)
}
Exemple #3
0
func TestNormalizeDate(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.NormalizeDate(date)
		hm := (norm.Hour() == 0) && (norm.Minute() == 0)
		sn := (norm.Second() == 0) && (norm.Nanosecond() == 0)
		tz := norm.Location() == util.Tz
		return hm && sn && tz
	}

	err := quick.Check(testf, &conf)
	if err != nil {
		t.Error(err)
	}
}
Exemple #4
0
//IsOverriddenDay tests if submitted time is during an overriden day.
func (c Config) IsOverriddenDay(t time.Time) bool {
	_, ok := c.OverrideDays[util.NormalizeDate(t).Unix()]
	return ok
}