scripts/treno: work around jq lacks of timezone support

Michele Guerini Rocco 2023-03-30 14:50:58 +02:00
parent 347c7ada63
commit 307b0213bf
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
1 changed files with 11 additions and 2 deletions

View File

@ -109,16 +109,25 @@ EOF
printf 'data: \033[36m%s\033[0m\n\n' "$(date -d "$3" +'%F %R')"
curl -s --json "$query" "$url/ticket/solutions" |
jq -r '
"%FT%T.000+01:00" as $timefmt |
"%FT%T.%G%z" as $timefmt |
# Functions to color text
def red($x): "\u001B[1;31m\($x)\u001B[0m";
def green($x): "\u001B[1;32m\($x)\u001B[0m";
def blue($x): "\u001B[1;34m\($x)\u001B[0m";
def parse_iso8601:
# Parse an ISO 8601 date with timezone information
capture("(?<no_tz>[^.]*)(?<frac_sec>\\.\\d+)?(?:(?:(?<tz_sgn>[-+])(?<tz_hr>\\d{2}):?(?<tz_min>\\d{2})?)|Z)$") |
(.no_tz + "Z" | fromdateiso8601)
+ ("0"+.frac_sec | tonumber)
- (.tz_sgn + "60" | tonumber)
* ((.tz_hr // "0" | tonumber) * 60 + (.tz_min // "0" | tonumber))
| todateiso8601 | strptime("%FT%TZ");
def time:
# Extracts "HH:MM" from a timestamp
strptime($timefmt) | mktime | strftime("%R");
parse_iso8601 | mktime | strftime("%R");
def delta($stop; $start):
# Computes the time elapsed between two dates