Skip to content

Instantly share code, notes, and snippets.

@hlubek
Created October 22, 2020 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlubek/f46a73bc9d150cf1f2af585b0849e3d9 to your computer and use it in GitHub Desktop.
Save hlubek/f46a73bc9d150cf1f2af585b0849e3d9 to your computer and use it in GitHub Desktop.
Go timezone bug (fixed in master) with current Alpine tzdata

How to reproduce

docker build -t timezone-bug:dev .
docker run --rm timezone-bug:dev
FROM golang:1.15 as builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -o bin/test
# ---
FROM alpine:3.12
RUN apk update &&\
apk --no-cache add tzdata &&\
rm -rf /var/cache/apk/*
COPY --from=builder /app/bin/test /app/test
CMD ["/app/test"]
package main
import (
"fmt"
"os"
"time"
)
func main() {
loc, err := time.LoadLocation("Europe/Berlin")
if err != nil {
failErr(fmt.Errorf("loading location %s: %v", "Europe/Berlin", err))
}
d := time.Date(2020, time.October, 29, 15, 30, 0, 0, loc)
expectedDate := "2020-10-29 15:30:00 +0100 CET"
actualDate := d.String()
if expectedDate != actualDate {
failErr(fmt.Errorf("expected %s, but date was interpreted as %s", expectedDate, actualDate))
}
}
func failErr(err error) {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment