From 955911653d08fe3e01ca61656a2eb9d67d1b38de Mon Sep 17 00:00:00 2001
From: James Page <james@bob.co.za>
Date: Fri, 6 Jan 2023 10:41:00 +0200
Subject: [PATCH] #35 Store current location in date-utils instead of
 retrieving it each time

---
 date_utils/date_utils.go | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/date_utils/date_utils.go b/date_utils/date_utils.go
index e456d79..d60b7c8 100644
--- a/date_utils/date_utils.go
+++ b/date_utils/date_utils.go
@@ -8,6 +8,8 @@ import (
 
 const TimeZoneString = "Africa/Johannesburg"
 
+var currentLocation *time.Location
+
 func DateLayoutYearMonthDayTimeT() string {
 	layout := "2006-01-02T15:04:05"
 	return layout
@@ -81,8 +83,10 @@ func DateDBFormattedStringDateOnly(date time.Time) string {
 }
 
 func CurrentLocation() *time.Location {
-	loc, _ := time.LoadLocation(TimeZoneString)
-	return loc
+	if currentLocation == nil {
+		currentLocation, _ = time.LoadLocation(TimeZoneString)
+	}
+	return currentLocation
 }
 
 func DateLocal(date *time.Time) {
-- 
GitLab