Add local ICal timestamp format, rename centralTime global var

This commit is contained in:
2024-01-29 02:31:42 -06:00
parent e0da185ff9
commit ef3df75f45
2 changed files with 20 additions and 19 deletions

27
main.go
View File

@@ -20,20 +20,21 @@ import (
)
var (
ctx context.Context
kv *redis.Client
session *discordgo.Session
client http.Client
cookies http.CookieJar
isDevelopment bool
baseURL string // Base URL for all requests to the banner system
environment string
centralTime *time.Location
ctx context.Context
kv *redis.Client
session *discordgo.Session
client http.Client
cookies http.CookieJar
isDevelopment bool
baseURL string // Base URL for all requests to the banner system
environment string
CentralTimeLocation *time.Location
)
const (
ICalTimestampFormatUtc = "20060102T150405Z"
CentralTimezone = "America/Chicago"
ICalTimestampFormatUtc = "20060102T150405Z"
ICalTimestampFormatLocal = "20060102T150405"
CentralTimezoneName = "America/Chicago"
)
func init() {
@@ -45,14 +46,14 @@ func init() {
ctx = context.Background()
var err error
centralTime, err = time.LoadLocation(CentralTimezone)
CentralTimeLocation, err = time.LoadLocation(CentralTimezoneName)
if err != nil {
panic(err)
}
// Set zerolog's timestamp function to use the central timezone
zerolog.TimestampFunc = func() time.Time {
return time.Now().In(centralTime)
return time.Now().In(CentralTimeLocation)
}
// Try to grab the environment variable, or default to development

12
term.go
View File

@@ -46,12 +46,12 @@ type YearDayRange struct {
// Summer: May 25th - August 15th
// Fall: August 18th - December 10th
func GetYearDayRange(year uint16) (YearDayRange, YearDayRange, YearDayRange) {
springStart := time.Date(int(year), time.January, 14, 0, 0, 0, 0, centralTime).YearDay()
springEnd := time.Date(int(year), time.May, 1, 0, 0, 0, 0, centralTime).YearDay()
summerStart := time.Date(int(year), time.May, 25, 0, 0, 0, 0, centralTime).YearDay()
summerEnd := time.Date(int(year), time.August, 15, 0, 0, 0, 0, centralTime).YearDay()
fallStart := time.Date(int(year), time.August, 18, 0, 0, 0, 0, centralTime).YearDay()
fallEnd := time.Date(int(year), time.December, 10, 0, 0, 0, 0, centralTime).YearDay()
springStart := time.Date(int(year), time.January, 14, 0, 0, 0, 0, CentralTimeLocation).YearDay()
springEnd := time.Date(int(year), time.May, 1, 0, 0, 0, 0, CentralTimeLocation).YearDay()
summerStart := time.Date(int(year), time.May, 25, 0, 0, 0, 0, CentralTimeLocation).YearDay()
summerEnd := time.Date(int(year), time.August, 15, 0, 0, 0, 0, CentralTimeLocation).YearDay()
fallStart := time.Date(int(year), time.August, 18, 0, 0, 0, 0, CentralTimeLocation).YearDay()
fallEnd := time.Date(int(year), time.December, 10, 0, 0, 0, 0, CentralTimeLocation).YearDay()
return YearDayRange{
Start: uint16(springStart),