From 85ff0dac525c17bb94caa8a3f9476e022ee678a8 Mon Sep 17 00:00:00 2001 From: bloved Date: Sat, 16 Jan 2021 00:11:54 +0100 Subject: [PATCH] - FIX: timetable eval time as "local time" (no UTC) - FIX: Dockerfile: added timezone configuration (defaults to CET), use TZ env var to change it --- Dockerfile.amd64 | 2 ++ Dockerfile.arm32v7 | 2 ++ Dockerfile.arm64v8 | 2 ++ README.md | 2 ++ dns_handler.go | 9 ++++++--- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Dockerfile.amd64 b/Dockerfile.amd64 index 0632b7b..5f6b923 100644 --- a/Dockerfile.amd64 +++ b/Dockerfile.amd64 @@ -10,9 +10,11 @@ FROM debian:latest RUN apt update RUN apt upgrade -y RUN apt install ca-certificates -y +RUN apt install tzdata -y RUN mkdir -p /opt/zabov WORKDIR /opt/zabov COPY --from=builder /go/src/zabov /opt/zabov EXPOSE 53/udp +ENV TZ Europe/Rome ENTRYPOINT ["/opt/zabov/zabov"] diff --git a/Dockerfile.arm32v7 b/Dockerfile.arm32v7 index 606e3d4..633f3ee 100644 --- a/Dockerfile.arm32v7 +++ b/Dockerfile.arm32v7 @@ -10,8 +10,10 @@ FROM arm32v7/debian:latest RUN apt update RUN apt upgrade -y RUN apt install ca-certificates -y +RUN apt install tzdata -y RUN mkdir -p /opt/zabov WORKDIR /opt/zabov COPY --from=builder /go/src/zabov /opt/zabov EXPOSE 53/udp +ENV TZ Europe/Rome ENTRYPOINT ["/opt/zabov/zabov"] diff --git a/Dockerfile.arm64v8 b/Dockerfile.arm64v8 index aa716eb..f1add2b 100644 --- a/Dockerfile.arm64v8 +++ b/Dockerfile.arm64v8 @@ -10,8 +10,10 @@ FROM arm64v8/debian:latest RUN apt update RUN apt upgrade -y RUN apt install ca-certificates -y +RUN apt install tzdata -y RUN mkdir -p /opt/zabov WORKDIR /opt/zabov COPY --from=builder /go/src/zabov /opt/zabov EXPOSE 53/udp +ENV TZ Europe/Rome ENTRYPOINT ["/opt/zabov/zabov"] diff --git a/README.md b/README.md index d38b8ba..2fbb528 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,8 @@ ipgroups: an array of ipgroup dictionaries # DOCKER Multistage Dockerfiles are provided for AMD64, ARMv7, ARM64V8 +NOTE: you shall use TZ env var to change docker image timezone. TZ defaults to CET. + # TODO: - ~~caching~~ diff --git a/dns_handler.go b/dns_handler.go index 01a388c..51db447 100644 --- a/dns_handler.go +++ b/dns_handler.go @@ -105,6 +105,8 @@ func init() { dns.TypeTA: "TypeTA", dns.TypeDLV: "TypeDLV", dns.TypeReserved: "TypeReserved"} + + fmt.Println("Local Time:", getLocalTime().Format(time.ANSIC)) } func logQuery(clientIP string, name string, reqType uint16, config string, timetable string, killed string) { @@ -136,8 +138,8 @@ func logQuery(clientIP string, name string, reqType uint16, config string, timet } } -func getCurTime() (time.Time, error) { - return time.Parse("15:04", time.Now().Format("15:04")) +func getLocalTime() time.Time { + return time.Now().Local() } func confFromTimeTable(timetable string) string { @@ -149,7 +151,8 @@ func confFromTimeTable(timetable string) string { return "default" } for _, ttentry := range tt.table { - now := time.Now() + now := getLocalTime() + nowHour := now.Hour() nowMinute := now.Minute() weekday := weekdays[now.Weekday()]