| 1 | #!/usr/bin/env bash |
| 2 | # Desc: Baltakatei's verbose date command |
| 3 | # Usage: bkdatev [args] |
| 4 | # Example: bkdatev --date="2001-09-11T09:02:59-04" |
| 5 | # Version: 0.2.2 |
| 6 | # Ref/Attrib: [1] "ISO 8601". Wikipedia. https://en.wikipedia.org/wiki/ISO_8601 |
| 7 | # [2] "Changing the Locale in Wine" https://stackoverflow.com/a/16428951 |
| 8 | # [3] "Shanghai vs Beijing" https://bugs.launchpad.net/ubuntu/+source/libgweather/+bug/228554 |
| 9 | # Notes: * Check `ls -R /usr/share/zoneinfo` for time zone names. |
| 10 | # * Check `cat /usr/share/i18n/SUPPORTED` for supported locales. |
| 11 | # * For list of valid locales, see: https://manpages.ubuntu.com/manpages/bionic/man3/DateTime::Locale::Catalog.3pm.html |
| 12 | # * Locations chosen for population, personal signifiance, and spatial coverage. |
| 13 | # * For International Atomic Time (TAI), use offsets from UTC provided in `/usr/share/zoneinfo/leap-seconds.list`. |
| 14 | |
| 15 | line_sep() { |
| 16 | # Input: var: n_ln |
| 17 | local skip_every=4; |
| 18 | ((n_ln++)); |
| 19 | if ! ((n_ln % "$skip_every")); then |
| 20 | printf "\n"; |
| 21 | fi; |
| 22 | return 0; |
| 23 | }; # periodically print separating blank line |
| 24 | print_dateline() { |
| 25 | # Input: var: $id |
| 26 | # var: $fs_1 |
| 27 | # var: $fs_2 |
| 28 | # var: $fs_3 |
| 29 | # args: $@ |
| 30 | # Output: stdout |
| 31 | # Depends: printf, date |
| 32 | # Ref/Attrib: * Truncate string in printf https://stackoverflow.com/a/46812677 |
| 33 | local s_1 s_2 s_3 s_4; |
| 34 | |
| 35 | s_1="$id"; |
| 36 | s_2="$(date "$@" "$fs_1")"; |
| 37 | s_3="$(date "$@" "$fs_2")"; |
| 38 | s_4="$(date "$@" "$fs_3")"; |
| 39 | |
| 40 | printf "%-10.10s %-25.25s (%-20.20s) (%s)" "$s_1" "$s_2" "$s_3" "$s_4"; |
| 41 | printf "\n"; |
| 42 | |
| 43 | unset fs_1 fs_2 fs_3 fs_4; |
| 44 | }; # print line of dates |
| 45 | main() { |
| 46 | n_ln=0; # for line_sep() |
| 47 | unset LC_TIME; # Fall back to time zone-specific locale settings. |
| 48 | |
| 49 | # format strings |
| 50 | fs_iso8601="+%Y-%m-%dT%H:%M:%S%:::z"; # typical ISO-8601 |
| 51 | fs_iso8601_etc="+%G-W%V-%u, %Y-%j"; # alternate ISO-8601 dates |
| 52 | fs_locale="+%Z; %A; %c"; # locale-specific date strings |
| 53 | |
| 54 | # vars for print_dateline() |
| 55 | fs_1="$fs_iso8601"; |
| 56 | fs_2="$fs_iso8601_etc"; |
| 57 | fs_3="$fs_locale"; |
| 58 | |
| 59 | # UTC (pop. (2021): 7,837,000,000) |
| 60 | ( |
| 61 | export TZ=UTC; |
| 62 | id="UTC"; |
| 63 | fs_3="+%s seconds since 1970-01-01T00:00+00"; |
| 64 | print_dateline "$@"; |
| 65 | ); line_sep; |
| 66 | |
| 67 | # Hawaii |
| 68 | ( |
| 69 | export TZ=US/Hawaii; |
| 70 | export LANG="haw-US.UTF8"; |
| 71 | id="HAWAII"; |
| 72 | print_dateline "$@"; |
| 73 | ); line_sep; |
| 74 | |
| 75 | # Los Angeles, USA |
| 76 | ( |
| 77 | export TZ=America/Los_Angeles; |
| 78 | export LANG="en_US.UTF-8"; |
| 79 | id="LOS ANGELES"; |
| 80 | print_dateline "$@"; |
| 81 | ); line_sep; |
| 82 | |
| 83 | # Denver, USA (pop. (2021): 711,463) |
| 84 | ( |
| 85 | export TZ=America/Denver; |
| 86 | export LANG="en_US.UTF-8"; |
| 87 | id="DENVER"; |
| 88 | print_dateline "$@"; |
| 89 | ); line_sep; |
| 90 | |
| 91 | # Chicago, USA (pop. (2021): 711,463) |
| 92 | ( |
| 93 | export TZ=America/Chicago; |
| 94 | export LANG="en_US.UTF-8"; |
| 95 | id="CHICAGO"; |
| 96 | print_dateline "$@"; |
| 97 | ); line_sep; |
| 98 | |
| 99 | # Mexico City, Mexico (pop. (2018): 21,804,515) |
| 100 | ( |
| 101 | export TZ=America/Mexico_City; |
| 102 | export LANG="es_MX.UTF8"; |
| 103 | id="MEXICO CITY"; |
| 104 | print_dateline "$@"; |
| 105 | ); line_sep; |
| 106 | |
| 107 | # Panama City, Panama |
| 108 | ( |
| 109 | export TZ=America/Panama; |
| 110 | export LANG="es_PA.UTF8"; |
| 111 | id="PANAMA CITY"; |
| 112 | print_dateline "$@"; |
| 113 | ); line_sep; |
| 114 | |
| 115 | # New York, USA (pop. (2018): 20,140,470) |
| 116 | ( |
| 117 | export TZ=America/New_York; |
| 118 | export LANG="en_US.UTF-8"; |
| 119 | id="NEW YORK"; |
| 120 | print_dateline "$@"; |
| 121 | ); line_sep; |
| 122 | |
| 123 | # São Paulo, Brazil |
| 124 | ( |
| 125 | export TZ=America/Sao_Paulo; |
| 126 | export LANG="pt_BR.UTF8"; |
| 127 | id="SAO PAULO"; |
| 128 | print_dateline "$@"; |
| 129 | ); line_sep; |
| 130 | |
| 131 | # Buenos Aires |
| 132 | ( |
| 133 | export TZ=America/Argentina/Buenos_Aires; |
| 134 | export LANG="es_AR.UTF8"; |
| 135 | id="BUENOS AIRES"; |
| 136 | print_dateline "$@"; |
| 137 | ); line_sep; |
| 138 | |
| 139 | # London, England |
| 140 | ( |
| 141 | export TZ=Europe/London; |
| 142 | export LANG="en_GB.UTF-8"; |
| 143 | id="LONDON"; |
| 144 | print_dateline "$@"; |
| 145 | ); line_sep; |
| 146 | |
| 147 | # Kinshasa, Africa |
| 148 | ( |
| 149 | export TZ=Africa/Kinshasa; |
| 150 | export LANG="ln_CD.UTF8"; |
| 151 | id="KINSHASA"; |
| 152 | print_dateline "$@"; |
| 153 | ); line_sep; |
| 154 | |
| 155 | # Lagos, Africa |
| 156 | ( |
| 157 | export TZ=Africa/Lagos; |
| 158 | export LANG="en_NG.UTF8"; |
| 159 | id="LAGOS"; |
| 160 | print_dateline "$@"; |
| 161 | ); line_sep; |
| 162 | |
| 163 | # Paris, France |
| 164 | ( |
| 165 | export TZ=Europe/Paris; |
| 166 | export LANG="fr_FR.UTF8"; |
| 167 | id="PARIS"; |
| 168 | print_dateline "$@"; |
| 169 | ); line_sep; |
| 170 | |
| 171 | # Stockholm, Sweden |
| 172 | ( |
| 173 | export TZ=Europe/Stockholm; |
| 174 | export LANG="sv_SE.UTF8"; |
| 175 | id="STOCKHOLM"; |
| 176 | print_dateline "$@"; |
| 177 | ); line_sep; |
| 178 | |
| 179 | # Cairo, Egypt |
| 180 | ( |
| 181 | export TZ=Africa/Cairo; |
| 182 | export LANG="ar_EG.UTF8"; |
| 183 | id="CAIRO"; |
| 184 | print_dateline "$@"; |
| 185 | ); line_sep; |
| 186 | |
| 187 | # Athens (pop. (2020): 3,526,887) |
| 188 | ( |
| 189 | export TZ=Europe/Athens; |
| 190 | export LANG="el_GR.UTF8"; |
| 191 | id="ATHENS"; |
| 192 | print_dateline "$@"; |
| 193 | ); line_sep; |
| 194 | |
| 195 | # Istanbul (pop. (2020): 13,719,061) |
| 196 | ( |
| 197 | export TZ=Asia/Istanbul; |
| 198 | export LANG="tr_TR.UTF8"; |
| 199 | id="ISTANBUL"; |
| 200 | print_dateline "$@"; |
| 201 | ); line_sep; |
| 202 | |
| 203 | # Tehran, Iran |
| 204 | ( |
| 205 | export TZ=Asia/Tehran; |
| 206 | export LANG="fa_IR.UTF8"; |
| 207 | id="TEHRAN"; |
| 208 | print_dateline "$@"; |
| 209 | ); line_sep; |
| 210 | |
| 211 | # Moscow, Russia |
| 212 | ( |
| 213 | export TZ=Europe/Moscow; |
| 214 | export LANG="ru_RU.UTF-8"; |
| 215 | id="MOSCOW"; |
| 216 | print_dateline "$@"; |
| 217 | ); line_sep; |
| 218 | |
| 219 | # Kyiv, Ukraine (pop. (2021): 2,962,180) |
| 220 | ( |
| 221 | export TZ=Europe/Kyiv; |
| 222 | export LANG="uk_UA.UTF-8"; |
| 223 | id="KYIV"; |
| 224 | print_dateline "$@"; |
| 225 | ); line_sep; |
| 226 | |
| 227 | # Delhi, India (pop. (2018): 29,000,000) |
| 228 | ( |
| 229 | export TZ=Asia/Kolkata; |
| 230 | export LANG="hi_IN.UTF-8"; |
| 231 | id="DELHI"; |
| 232 | print_dateline "$@"; |
| 233 | ); line_sep; |
| 234 | |
| 235 | # Jakarta, Indonesia (pop. (2018): 33,430,285) |
| 236 | ( |
| 237 | export TZ=Asia/Jakarta; |
| 238 | export LANG="id_ID.UTF8"; |
| 239 | id="JAKARTA"; |
| 240 | print_dateline "$@"; |
| 241 | ); line_sep; |
| 242 | |
| 243 | # Singapore, Singapore (pop (2018): 5,792,000) |
| 244 | ( |
| 245 | export TZ=Asia/Singapore; |
| 246 | export LANG="en_SG.UTF-8"; |
| 247 | id="SINGAPORE"; |
| 248 | print_dateline "$@"; |
| 249 | ); line_sep; |
| 250 | |
| 251 | # Beijing, China (pop. (2018): 19,618,000) |
| 252 | ( |
| 253 | export TZ=Asia/Shanghai; # [3] |
| 254 | export LANG="zh_CN.UTF-8"; |
| 255 | id="BEIJING"; |
| 256 | print_dateline "$@"; |
| 257 | ); line_sep; |
| 258 | |
| 259 | # Taipei, Taiwan (pop (2019): 7,034,084) |
| 260 | ( |
| 261 | export TZ=Asia/Taipei; # [3] |
| 262 | export LANG="zh_TW.UTF-8"; |
| 263 | id="TAIPEI"; |
| 264 | print_dateline "$@"; |
| 265 | ); line_sep; |
| 266 | |
| 267 | # Tokyo, Japan (pop. (2018): 37,274,000) |
| 268 | ( |
| 269 | export TZ=Asia/Tokyo; |
| 270 | export LANG="ja_JP.UTF8"; |
| 271 | id="TOKYO"; |
| 272 | print_dateline "$@"; |
| 273 | ); line_sep; |
| 274 | |
| 275 | # Seoul, South Korea (pop. (2018): 25,514,000) |
| 276 | ( |
| 277 | export TZ=Asia/Seoul; |
| 278 | export LANG="ko_KR.UTF8"; |
| 279 | id="SEOUL"; |
| 280 | print_dateline "$@"; |
| 281 | ); line_sep; |
| 282 | |
| 283 | # Pyongyang, North Korea |
| 284 | ( |
| 285 | export TZ=Asia/Pyongyang; |
| 286 | export LANG="ko_KP.UTF8"; |
| 287 | id="PYONGYANG"; |
| 288 | print_dateline "$@"; |
| 289 | ); line_sep; |
| 290 | |
| 291 | # Sydney, Australia |
| 292 | ( |
| 293 | export TZ=Australia/Sydney; |
| 294 | export LANG="en_AU.UTF8"; |
| 295 | id="SYDNEY"; |
| 296 | print_dateline "$@"; |
| 297 | ); line_sep; |
| 298 | |
| 299 | # Guam |
| 300 | ( |
| 301 | export TZ=Pacific/Guam; |
| 302 | export LANG="en_GU.UTF8"; |
| 303 | id="GUAM"; |
| 304 | print_dateline "$@"; |
| 305 | ); line_sep; |
| 306 | |
| 307 | # Auckland, New Zealand |
| 308 | ( |
| 309 | export TZ=Pacific/Auckland; |
| 310 | export LANG="en_NZ.UTF8"; |
| 311 | id="AUCKLAND"; |
| 312 | print_dateline "$@"; |
| 313 | ); line_sep; |
| 314 | |
| 315 | return 0; |
| 316 | }; # main program |
| 317 | |
| 318 | main "$@"; |