Refactor everything
This commit is contained in:
parent
b56ce43c80
commit
57903d4724
45 changed files with 514 additions and 416 deletions
31
internal/config/time.go
Normal file
31
internal/config/time.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
// FIXME: This probably shouldn't be part of config package
|
||||
|
||||
// Grace returns whether the grace period is active.
|
||||
// NOTE: Grace period has minute precision
|
||||
func (c Config) Grace() bool {
|
||||
t := time.Now().In(c.Timezone)
|
||||
active := (60*t.Hour() + t.Minute()) < int(c.GraceTime.Minutes())
|
||||
if active {
|
||||
slog.Debug("grace period active",
|
||||
"time", 60*t.Hour()+t.Minute(),
|
||||
"grace", c.GraceTime.Minutes())
|
||||
}
|
||||
return active
|
||||
}
|
||||
|
||||
// TodayDate returns today's formatted date. It accounts for Config.GraceTime.
|
||||
func (c Config) TodayDate() string {
|
||||
dateFormatted := time.Now().In(c.Timezone).Format(time.DateOnly)
|
||||
if c.Grace() {
|
||||
dateFormatted = time.Now().In(c.Timezone).AddDate(0, 0, -1).Format(time.DateOnly)
|
||||
}
|
||||
slog.Debug("today", "time", time.Now().In(c.Timezone).Format(time.DateTime))
|
||||
return dateFormatted
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue