diff --git a/internal/timezone/timezone.go b/internal/timezone/timezone.go index c0746945..1efd803d 100644 --- a/internal/timezone/timezone.go +++ b/internal/timezone/timezone.go @@ -4,9 +4,14 @@ package timezone // import "miniflux.app/v2/internal/timezone" import ( + "sync" "time" ) +var ( + tzCache = sync.Map{} // Cache for time locations to avoid loading them multiple times. +) + // Convert converts provided date time to actual timezone. func Convert(tz string, t time.Time) time.Time { userTimezone := getLocation(tz) @@ -42,9 +47,15 @@ func Now(tz string) time.Time { } func getLocation(tz string) *time.Location { + if loc, ok := tzCache.Load(tz); ok { + return loc.(*time.Location) + } + loc, err := time.LoadLocation(tz) if err != nil { loc = time.Local } + + tzCache.Store(tz, loc) return loc }