Skip to content

Commit 85d3bca

Browse files
authored
perf: avoid LoadLocation syscall for each TibiaDataDatetime call (#629)
1 parent 2942cc4 commit 85d3bca

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/TibiaDataUtils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
"golang.org/x/text/unicode/norm"
1717
)
1818

19+
// berlinLocation is cached to avoid repeated time.LoadLocation calls per request.
20+
var berlinLocation, _ = time.LoadLocation("Europe/Berlin")
21+
1922
// TibiaDataDatetime func
2023
func TibiaDataDatetime(date string) string {
2124
//TODO: Normalization needs to happen above this layer
@@ -31,14 +34,11 @@ func TibiaDataDatetime(date string) string {
3134
// The string that should be returned is the current timestamp
3235
returnDate = time.Now()
3336
} else {
34-
// timezone use in html: CET/CEST
35-
loc, _ := time.LoadLocation("Europe/Berlin")
36-
3737
// format used in datetime on html: Jan 02 2007, 19:20:30 CET
3838
formatting := "Jan 02 2006, 15:04:05 MST"
3939

4040
// parsing html in time with location set in loc
41-
returnDate, err = time.ParseInLocation(formatting, date, loc)
41+
returnDate, err = time.ParseInLocation(formatting, date, berlinLocation)
4242

4343
// parsing html in tiem without loc
4444
//returnDate, err = time.Parse("Jan 02 2006, 15:04:05 MST", date)

0 commit comments

Comments
 (0)