From 9bb104c9f4bb1a424791861429117d79b2efb97f Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Sun, 22 Feb 2026 11:12:50 -0800 Subject: [PATCH] Fix timezone offset handling in epoch conversion The jq epoch helper was discarding timezone offsets (e.g. -08:00) and treating local time as UTC. Now parses the offset with capture() and applies it correctly: -08:00 adds 8h, +05:30 subtracts 5h30m. Co-Authored-By: Claude Opus 4.6 --- ansible/roles/forgejo_metrics/templates/forgejo-metrics.sh.j2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ansible/roles/forgejo_metrics/templates/forgejo-metrics.sh.j2 b/ansible/roles/forgejo_metrics/templates/forgejo-metrics.sh.j2 index 0afb488..365b62b 100644 --- a/ansible/roles/forgejo_metrics/templates/forgejo-metrics.sh.j2 +++ b/ansible/roles/forgejo_metrics/templates/forgejo-metrics.sh.j2 @@ -18,7 +18,8 @@ api() { } # jq helper: convert ISO 8601 timestamp (with any tz offset) to epoch seconds -JQ_EPOCH='def epoch: sub("[.][0-9]+"; "") | sub("[+-][0-9][0-9]:[0-9][0-9]$"; "Z") | sub("ZZ$"; "Z") | fromdate;' +# jq's fromdate only handles Z, so we parse the offset and apply it manually +JQ_EPOCH='def epoch: sub("[.][0-9]+"; "") | if test("[+-][0-9]{2}:[0-9]{2}$") then capture("^(?
.*)(?[+-])(?[0-9]{2}):(?[0-9]{2})$") | (.dt + "Z" | fromdate) as $base | ((.h | tonumber) * 3600 + (.m | tonumber) * 60) as $off | if .sign == "-" then $base + $off else $base - $off end else sub("Z$"; "") + "Z" | fromdate end;' forgejo_up=0 if curl -sf "${FORGEJO_URL}/api/v1/version" >/dev/null 2>&1; then