Skip to content

feat: support TZ environment variable for timezone configuration#7054

Open
Mothball7205 wants to merge 1 commit into
stashapp:developfrom
Mothball7205:fix/docker-tz
Open

feat: support TZ environment variable for timezone configuration#7054
Mothball7205 wants to merge 1 commit into
stashapp:developfrom
Mothball7205:fix/docker-tz

Conversation

@Mothball7205

@Mothball7205 Mothball7205 commented Jun 16, 2026

Copy link
Copy Markdown

Description

go lang already supports TZ as mentioned in their time package docs:

... On Unix systems, Local consults the TZ environment variable to find the time zone to use. No TZ means use the system default /etc/localtime. TZ="" means use UTC. TZ="foo" means use file foo in the system timezone directory.

this adds time/tzdata package as a fallback timezone database. it's very well explained in their docs:

Package tzdata provides an embedded copy of the timezone database. If this package is imported anywhere in the program, then if the time package cannot find tzdata files on the system, it will use this embedded information.

Importing this package will increase the size of a program by about 450 KB.

this is a backup in case tzdata doesnt exist (stashapp already adds tzdata in the docker/ci/x86_64/Dockerfile. but its better to have this fallback).
also adjusted the example docker-compose.yaml

Related Issue

#1238

Testing

Testing files:

//go:build withtz
package main

import (
      "fmt"
      "time"
      _ "time/tzdata"
)

func main() {
      fmt.Println("local time:", time.Now().Format("2006-01-02 15:04:05 MST -0700"))
}
//go:build !withtz
package main

import (
      "fmt"
      "time"
)

func main() {
      fmt.Println("local time:", time.Now().Format("2006-01-02 15:04:05 MST -0700"))
}

Test run (pure alpine):

docker run --rm -v /tmp/tztest:/t:ro -e TZ=America/New_York alpine:latest sh -c 'echo "tzdata installed: $(test -d /usr/share/zoneinfo && echo yes || echo no)"; echo -n "WITHOUT embed: "; /t/tz_without; echo -n "WITH embed:    "; /t/tz_with'

Results:

tzdata installed: no
WITHOUT embed: local time: 2026-06-13 00:45:20 UTC +0000
WITH embed:    local time: 2026-06-12 20:45:20 EDT -0400

Test run (alpine with tzdata installed):

docker run --rm -v /tmp/tztest:/t:ro -e TZ=America/New_York alpine:latest sh -c 'apk add -q tzdata && echo -n "WITHOUT embed + system tzdata: " && /t/tz_without'

Results:

WITHOUT embed + system tzdata: local time: 2026-06-12 20:45:33 EDT -0400

Checklist

  • I have read and understood the Contributing document.
  • I have read and understood the AI Usage Policy document.
  • I have made corresponding changes to the documentation (if applicable).

AI Usage Disclosure

  • I have used AI tools to assist with this pull request, and I have disclosed the tools and how I used them below.

I did use claude code to generate the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant