- Note: If arguments to `bkdatev` are not passed to the `date` call in
the `get_tz_offset()` function, the time zone offset displayed will be
that of the user's current time, not the historical time they might
specify via an option like `--date="1941-12-07T07:48-10:30"`; in this
particular example, the reported time for Hawaii would be
`1941-12-07T07:48-10` if the command were run in the year 2023 when
Hawaii's time zone offset is `UTC-10` instead of `UT/GMT-10:30` as it
was in the year 1941.
# Desc: Baltakatei's verbose date command
# Usage: bkdatev [args]
# Example: bkdatev --date="2001-09-11T09:02:59-04"
# Desc: Baltakatei's verbose date command
# Usage: bkdatev [args]
# Example: bkdatev --date="2001-09-11T09:02:59-04"
# Depends: GNU Coreutils 8.32, Bash 3.2.57
# Ref/Attrib: [1] "ISO 8601". Wikipedia. https://en.wikipedia.org/wiki/ISO_8601
# [2] "Changing the Locale in Wine" https://stackoverflow.com/a/16428951
# Depends: GNU Coreutils 8.32, Bash 3.2.57
# Ref/Attrib: [1] "ISO 8601". Wikipedia. https://en.wikipedia.org/wiki/ISO_8601
# [2] "Changing the Locale in Wine" https://stackoverflow.com/a/16428951
# Desc: Get from 'date' the timezone UTC offset in a way
# compatible with both GNU Coreutils and BSD versions.
# Input: env var: TZ (time zone for date; e.g. 'America/Denver')
# Desc: Get from 'date' the timezone UTC offset in a way
# compatible with both GNU Coreutils and BSD versions.
# Input: env var: TZ (time zone for date; e.g. 'America/Denver')
+ # args: $@ # passed onto `date`
# Depends: date (GNU Coreutils 8.32 or BSD), rev
local ntz ntz ntz_out;
local last2;
# Get numeric time zone string in way compatible with GNU Coreutils and BSD
# Depends: date (GNU Coreutils 8.32 or BSD), rev
local ntz ntz ntz_out;
local last2;
# Get numeric time zone string in way compatible with GNU Coreutils and BSD
- ntz="$(date "+%z")"; # e.g. "+0530"
+ ntz="$(date "+%z" "$@")"; # e.g. "+0530"
# Check if last two characters are trailing zeros that can be removed.
last2="${ntz:3:2}"; # assumes $ntz is 5 characters (i.e. "±HHMM")
# Check if last two characters are trailing zeros that can be removed.
last2="${ntz:3:2}"; # assumes $ntz is 5 characters (i.e. "±HHMM")
# var: $fs_1
# var: $fs_2
# var: $fs_3
# var: $fs_1
# var: $fs_2
# var: $fs_3
+ # args: $@ # passed on to `date`
# env var: TZ (time zone for date; e.g. 'America/Denver')
# Output: stdout
# Depends: printf, date
# env var: TZ (time zone for date; e.g. 'America/Denver')
# Output: stdout
# Depends: printf, date
s_2="$(date "$@" "$fs_1")"; # ISO-8601 without numeric timezone
s_3="$(date "$@" "$fs_2")"; # Alternate ISO-8601 expressions
s_4="$(date "$@" "$fs_3")"; # locale-specific date strings
s_2="$(date "$@" "$fs_1")"; # ISO-8601 without numeric timezone
s_3="$(date "$@" "$fs_2")"; # Alternate ISO-8601 expressions
s_4="$(date "$@" "$fs_3")"; # locale-specific date strings
# Append numeric timezone to $s_2 with appropriate format
# (e.g. '-07' for 'Arizona', '+05:45' for 'Asia/Kathmandu')
# Append numeric timezone to $s_2 with appropriate format
# (e.g. '-07' for 'Arizona', '+05:45' for 'Asia/Kathmandu')
- s_2_tz="$(get_tz_offset)";
+ s_2_tz="$(get_tz_offset "$@")";
s_2="$( printf "%s%s" "$s_2" "$s_2_tz" )";
printf "%-10.10s %-25.25s (%-20.20s) (%s)" "$s_1" "$s_2" "$s_3" "$s_4";
s_2="$( printf "%s%s" "$s_2" "$s_2_tz" )";
printf "%-10.10s %-25.25s (%-20.20s) (%s)" "$s_1" "$s_2" "$s_3" "$s_4";