From 4143a6ead723ffe633c8d4d893fd8de5edff7c3b Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Fri, 11 Nov 2022 21:49:04 +0000 Subject: [PATCH] feat(user/bkdatev):Script to print various verbose iso-8601 dates --- user/bkdatev | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100755 user/bkdatev diff --git a/user/bkdatev b/user/bkdatev new file mode 100755 index 0000000..b888d57 --- /dev/null +++ b/user/bkdatev @@ -0,0 +1,299 @@ +#!/usr/bin/env bash +# Desc: Baltakatei's verbose date command +# Usage: bkdatev [args] +# Example: bkdatev --date="2001-09-11T09:02:59-04" +# Version: 0.0.1 +# Ref/Attrib: [1] "ISO 8601". Wikipedia. https://en.wikipedia.org/wiki/ISO_8601 +# [2] "Changing the Locale in Wine" https://stackoverflow.com/a/16428951 +# [3] "Shanghai vs Beijing" https://bugs.launchpad.net/ubuntu/+source/libgweather/+bug/228554 +# Notes: * Check `ls -R /usr/share/zoneinfo` for time zone names. +# * Check `cat /usr/share/i18n/SUPPORTED` for supported locales. +# * For list of valid locales, see: https://manpages.ubuntu.com/manpages/bionic/man3/DateTime::Locale::Catalog.3pm.html +# * Locations chosen for population, personal signifiance, and spatial coverage. + +line_sep() { + # Input: var: n_ln + local skip_every=4; + ((n_ln++)); + if ! ((n_ln % "$skip_every")); then + printf "\n"; + fi; + return 0; +}; # periodically print separating blank line +print_dateline() { + # Input: var: $id + # var: $fs_1 + # var: $fs_2 + # var: $fs_3 + # args: $@ + # Output: stdout + # Depends: printf, date + # Ref/Attrib: * Truncate string in printf https://stackoverflow.com/a/46812677 + local s_1 s_2 s_3 s_4; + + s_1="$id"; + s_2="$(date "$@" "$fs_1")"; + s_3="$(date "$@" "$fs_2")"; + s_4="$(date "$@" "$fs_3")"; + + printf "%-10.10s %-25.25s (%-20.20s) (%s)" "$s_1" "$s_2" "$s_3" "$s_4"; + printf "\n"; + + unset fs_1 fs_2 fs_3 fs_4; + }; # print line of dates +main() { + n_ln=0; # for line_sep() + + # format strings + fs_iso8601="+%Y-%m-%dT%H:%M:%S%:::z"; # typical ISO-8601 + fs_iso8601_etc="+%G-W%V-%u, %Y-%j"; # alternate ISO-8601 dates + fs_locale="+%Z; %A; %c"; # locale-specific date strings + + # vars for print_dateline() + fs_1="$fs_iso8601"; + fs_2="$fs_iso8601_etc"; + fs_3="$fs_locale"; + + # UTC (pop. (2021): 7,837,000,000) + ( + export TZ=UTC; + id="UTC"; + print_dateline "$@"; + ); line_sep; + + # Hawaii + ( + export TZ=US/Hawaii; + export LANG="haw-US.UTF8"; + id="HAWAII"; + print_dateline "$@"; + ); line_sep; + + # Los Angeles, USA + ( + export TZ=America/Los_Angeles; + export LANG="en_US.UTF-8"; + id="LOS ANGELES"; + print_dateline "$@"; + ); line_sep; + + # Denver, USA (pop. (2021): 711,463) + ( + export TZ=America/Denver; + export LANG="en_US.UTF-8"; + id="DENVER"; + print_dateline "$@"; + ); line_sep; + + # Chicago, USA (pop. (2021): 711,463) + ( + export TZ=America/Chicago; + export LANG="en_US.UTF-8"; + id="CHICAGO"; + print_dateline "$@"; + ); line_sep; + + # Mexico City, Mexico (pop. (2018): 21,804,515) + ( + export TZ=America/Mexico_City; + export LANG="es_MX.UTF8"; + id="MEXICO CITY"; + print_dateline "$@"; + ); line_sep; + + # Panama City, Panama + ( + export TZ=America/Panama; + export LANG="es_PA.UTF8"; + id="PANAMA CITY"; + print_dateline "$@"; + ); line_sep; + + # New York, USA (pop. (2018): 20,140,470) + ( + export TZ=America/New_York; + export LANG="en_US.UTF-8"; + id="NEW YORK"; + print_dateline "$@"; + ); line_sep; + + # São Paulo, Brazil + ( + export TZ=America/Sao_Paulo; + export LANG="pt_BR.UTF8"; + id="SAO PAULO"; + print_dateline "$@"; + ); line_sep; + + # Buenos Aires + ( + export TZ=America/Argentina/Buenos_Aires; + export LANG="es_AR.UTF8"; + id="BUENOS AIRES"; + print_dateline "$@"; + ); line_sep; + + # London, England + ( + export TZ=Europe/London; + export LANG="en_GB.UTF-8"; + id="LONDON"; + print_dateline "$@"; + ); line_sep; + + # Kinshasa, Africa + ( + export TZ=Africa/Kinshasa; + export LANG="ln_CD.UTF8"; + id="KINSHASA"; + print_dateline "$@"; + ); line_sep; + + # Lagos, Africa + ( + export TZ=Africa/Lagos; + export LANG="en_NG.UTF8"; + id="LAGOS"; + print_dateline "$@"; + ); line_sep; + + # Paris, France + ( + export TZ=Europe/Paris; + export LANG="fr_FR.UTF8"; + id="PARIS"; + print_dateline "$@"; + ); line_sep; + + # Stockholm, Sweden + ( + export TZ=Europe/Stockholm; + export LANG="sv_SE.UTF8"; + id="STOCKHOLM"; + print_dateline "$@"; + ); line_sep; + + # Cairo, Egypt + ( + export TZ=Africa/Cairo; + export LANG="ar_EG.UTF8"; + id="CAIRO"; + print_dateline "$@"; + ); line_sep; + + # Athens (pop. (2020): 3,526,887) + ( + export TZ=Europe/Athens; + export LANG="el_GR.UTF8"; + id="ATHENS"; + print_dateline "$@"; + ); line_sep; + + # Istanbul (pop. (2020): 13,719,061) + ( + export TZ=Asia/Istanbul; + export LANG="tr_TR.UTF8"; + id="ISTANBUL"; + print_dateline "$@"; + ); line_sep; + + # Tehran, Iran + ( + export TZ=Asia/Tehran; + export LANG="fa_IR.UTF8"; + id="TEHRAN"; + print_dateline "$@"; + ); line_sep; + + # Moscow, Russia + ( + export TZ=Europe/Moscow; + export LANG="ru_RU.UTF-8"; + id="MOSCOW"; + print_dateline "$@"; + ); line_sep; + + # Kyiv, Ukraine (pop. (2021): 2,962,180) + ( + export TZ=Europe/Kyiv; + export LANG="uk_UA.UTF-8"; + id="KYIV"; + print_dateline "$@"; + ); line_sep; + + # Delhi, India (pop. (2018): 29,000,000) + ( + export TZ=Asia/Kolkata; + export LANG="hi_IN.UTF-8"; + id="DELHI"; + print_dateline "$@"; + ); line_sep; + + # Jakarta, Indonesia (pop. (2018): 33,430,285) + ( + export TZ=Asia/Jakarta; + export LANG="id_ID.UTF8"; + id="JAKARTA"; + print_dateline "$@"; + ); line_sep; + + # Singapore, Singapore (pop (2018): 5,792,000) + ( + export TZ=Asia/Singapore; + export LANG="en_SG.UTF-8"; + id="SINGAPORE"; + print_dateline "$@"; + ); line_sep; + + # Beijing, China (pop. (2018): 19,618,000) + ( + export TZ=Asia/Shanghai; # [3] + export LANG="zh_CN.UTF-8"; + id="BEIJING"; + print_dateline "$@"; + ); line_sep; + + # Tokyo, Japan (pop. (2018): 37,274,000) + ( + export TZ=Asia/Tokyo; + export LANG="ja_JP.UTF8"; + id="TOKYO"; + print_dateline "$@"; + ); line_sep; + + # Seoul, South Korea (pop. (2018): 25,514,000) + ( + export TZ=Asia/Seoul; + export LANG="ko_KR.UTF8"; + id="SEOUL"; + print_dateline "$@"; + ); line_sep; + + # Sydney, Australia + ( + export TZ=Australia/Sydney; + export LANG="en_AU.UTF8"; + id="SYDNEY"; + print_dateline "$@"; + ); line_sep; + + # Guam + ( + export TZ=Pacific/Guam; + export LANG="en_GU.UTF8"; + id="GUAM"; + print_dateline "$@"; + ); line_sep; + + # Auckland, New Zealand + ( + export TZ=Pacific/Auckland; + export LANG="en_NZ.UTF8"; + id="AUCKLAND"; + print_dateline "$@"; + ); line_sep; + + return 0; +}; # main program + +main "$@"; -- 2.30.2