Use system or default TZ env var
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
nemunaire 2022-12-23 22:32:11 +01:00
parent cbf0fcd25a
commit 2c146f5615
5 changed files with 4 additions and 7 deletions

1
app.go
View File

@ -65,7 +65,6 @@ func (app *App) Start() {
Handler: app.router,
}
log.Println("Current timezone:", app.cfg.Timezone.String())
app.ResetTimer()
log.Printf("Ready, listening on %s\n", app.cfg.Bind)

View File

@ -17,7 +17,6 @@ func (c *Config) declareFlags() {
flag.StringVar(&c.ActionsDir, "actions-dir", c.ActionsDir, "Path to the directory containing the actions")
flag.StringVar(&c.RoutinesDir, "routines-dir", c.RoutinesDir, "Path to the directory containing the routines")
flag.IntVar(&c.SampleRate, "samplerate", c.SampleRate, "Samplerate for unifying output stream")
flag.Var(&c.Timezone, "timezone", "Timezone to use when dealing with times")
// Others flags are declared in some other files when they need specials configurations
}

View File

@ -18,7 +18,6 @@ type Config struct {
ActionsDir string
RoutinesDir string
Timezone Timezone
SampleRate int
}

View File

@ -174,7 +174,7 @@ func (a *AlarmRepeated) FillExcepts(cfg *config.Config, db *LevelDBStorage) erro
end := time.Time(*exception.End).AddDate(0, 0, 1)
for t := time.Time(*exception.Start); end.After(t); t = t.AddDate(0, 0, 1) {
if t.Weekday() == a.Weekday {
a.Excepts = append(a.Excepts, time.Date(t.Year(), t.Month(), t.Day(), time.Time(*a.StartTime).Hour(), time.Time(*a.StartTime).Minute(), time.Time(*a.StartTime).Second(), 0, cfg.Timezone.GetLocation()))
a.Excepts = append(a.Excepts, time.Date(t.Year(), t.Month(), t.Day(), time.Time(*a.StartTime).Hour(), time.Time(*a.StartTime).Minute(), time.Time(*a.StartTime).Second(), 0, time.Local))
t = t.AddDate(0, 0, 6)
}
}
@ -196,7 +196,7 @@ func (a *AlarmRepeated) GetNextOccurence(cfg *config.Config, db *LevelDBStorage)
now := time.Now()
today := time.Date(now.Year(), now.Month(), now.Day(), time.Time(*a.StartTime).Hour(), time.Time(*a.StartTime).Minute(), time.Time(*a.StartTime).Second(), 0, cfg.Timezone.GetLocation())
today := time.Date(now.Year(), now.Month(), now.Day(), time.Time(*a.StartTime).Hour(), time.Time(*a.StartTime).Minute(), time.Time(*a.StartTime).Second(), 0, time.Local)
if now.After(today) {
today = today.AddDate(0, 0, 1)
}

View File

@ -82,8 +82,8 @@ func DeclareNoJSRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelD
return
}
_, offset := alarm.Zone()
alarm = alarm.Truncate(24 * time.Hour).Add(-time.Duration(offset)*time.Second + duration)
alarm = alarm.Local().Truncate(24 * time.Hour)
alarm = alarm.Add(-time.Duration(alarm.Hour())*time.Hour + duration)
}
if time.Now().After(alarm) {