docker build -t timezone-bug:dev .
docker run --rm timezone-bug:dev
Created
October 22, 2020 06:39
-
-
Save hlubek/f46a73bc9d150cf1f2af585b0849e3d9 to your computer and use it in GitHub Desktop.
Go timezone bug (fixed in master) with current Alpine tzdata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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