Commit | Line | Data |
---|---|---|
4143a6ea SBS |
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" | |
514ae735 | 5 | # Version: 0.2.1 |
4143a6ea SBS |
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. | |
514ae735 | 13 | # * For International Atomic Time (TAI), use offsets from UTC provided in `/usr/share/zoneinfo/leap-seconds.list`. |
4143a6ea SBS |
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 | ||
48 | # format strings | |
49 | fs_iso8601="+%Y-%m-%dT%H:%M:%S%:::z"; # typical ISO-8601 | |
50 | fs_iso8601_etc="+%G-W%V-%u, %Y-%j"; # alternate ISO-8601 dates | |
51 | fs_locale="+%Z; %A; %c"; # locale-specific date strings | |
52 | ||
53 | # vars for print_dateline() | |
54 | fs_1="$fs_iso8601"; | |
55 | fs_2="$fs_iso8601_etc"; | |
56 | fs_3="$fs_locale"; | |
57 | ||
58 | # UTC (pop. (2021): 7,837,000,000) | |
59 | ( | |
60 | export TZ=UTC; | |
61 | id="UTC"; | |
e202e295 | 62 | fs_3="+%s seconds since 1970-01-01T00:00+00"; |
4143a6ea SBS |
63 | print_dateline "$@"; |
64 | ); line_sep; | |
65 | ||
66 | # Hawaii | |
67 | ( | |
68 | export TZ=US/Hawaii; | |
69 | export LANG="haw-US.UTF8"; | |
70 | id="HAWAII"; | |
71 | print_dateline "$@"; | |
72 | ); line_sep; | |
73 | ||
74 | # Los Angeles, USA | |
75 | ( | |
76 | export TZ=America/Los_Angeles; | |
77 | export LANG="en_US.UTF-8"; | |
78 | id="LOS ANGELES"; | |
79 | print_dateline "$@"; | |
80 | ); line_sep; | |
81 | ||
82 | # Denver, USA (pop. (2021): 711,463) | |
83 | ( | |
84 | export TZ=America/Denver; | |
85 | export LANG="en_US.UTF-8"; | |
86 | id="DENVER"; | |
87 | print_dateline "$@"; | |
88 | ); line_sep; | |
89 | ||
90 | # Chicago, USA (pop. (2021): 711,463) | |
91 | ( | |
92 | export TZ=America/Chicago; | |
93 | export LANG="en_US.UTF-8"; | |
94 | id="CHICAGO"; | |
95 | print_dateline "$@"; | |
96 | ); line_sep; | |
97 | ||
98 | # Mexico City, Mexico (pop. (2018): 21,804,515) | |
99 | ( | |
100 | export TZ=America/Mexico_City; | |
101 | export LANG="es_MX.UTF8"; | |
102 | id="MEXICO CITY"; | |
103 | print_dateline "$@"; | |
104 | ); line_sep; | |
105 | ||
106 | # Panama City, Panama | |
107 | ( | |
108 | export TZ=America/Panama; | |
109 | export LANG="es_PA.UTF8"; | |
110 | id="PANAMA CITY"; | |
111 | print_dateline "$@"; | |
112 | ); line_sep; | |
113 | ||
114 | # New York, USA (pop. (2018): 20,140,470) | |
115 | ( | |
116 | export TZ=America/New_York; | |
117 | export LANG="en_US.UTF-8"; | |
118 | id="NEW YORK"; | |
119 | print_dateline "$@"; | |
120 | ); line_sep; | |
121 | ||
122 | # São Paulo, Brazil | |
123 | ( | |
124 | export TZ=America/Sao_Paulo; | |
125 | export LANG="pt_BR.UTF8"; | |
126 | id="SAO PAULO"; | |
127 | print_dateline "$@"; | |
128 | ); line_sep; | |
129 | ||
130 | # Buenos Aires | |
131 | ( | |
132 | export TZ=America/Argentina/Buenos_Aires; | |
133 | export LANG="es_AR.UTF8"; | |
134 | id="BUENOS AIRES"; | |
135 | print_dateline "$@"; | |
136 | ); line_sep; | |
137 | ||
138 | # London, England | |
139 | ( | |
140 | export TZ=Europe/London; | |
141 | export LANG="en_GB.UTF-8"; | |
142 | id="LONDON"; | |
143 | print_dateline "$@"; | |
144 | ); line_sep; | |
145 | ||
146 | # Kinshasa, Africa | |
147 | ( | |
148 | export TZ=Africa/Kinshasa; | |
149 | export LANG="ln_CD.UTF8"; | |
150 | id="KINSHASA"; | |
151 | print_dateline "$@"; | |
152 | ); line_sep; | |
153 | ||
154 | # Lagos, Africa | |
155 | ( | |
156 | export TZ=Africa/Lagos; | |
157 | export LANG="en_NG.UTF8"; | |
158 | id="LAGOS"; | |
159 | print_dateline "$@"; | |
160 | ); line_sep; | |
161 | ||
162 | # Paris, France | |
163 | ( | |
164 | export TZ=Europe/Paris; | |
165 | export LANG="fr_FR.UTF8"; | |
166 | id="PARIS"; | |
167 | print_dateline "$@"; | |
168 | ); line_sep; | |
169 | ||
170 | # Stockholm, Sweden | |
171 | ( | |
172 | export TZ=Europe/Stockholm; | |
173 | export LANG="sv_SE.UTF8"; | |
174 | id="STOCKHOLM"; | |
175 | print_dateline "$@"; | |
176 | ); line_sep; | |
177 | ||
178 | # Cairo, Egypt | |
179 | ( | |
180 | export TZ=Africa/Cairo; | |
181 | export LANG="ar_EG.UTF8"; | |
182 | id="CAIRO"; | |
183 | print_dateline "$@"; | |
184 | ); line_sep; | |
185 | ||
186 | # Athens (pop. (2020): 3,526,887) | |
187 | ( | |
188 | export TZ=Europe/Athens; | |
189 | export LANG="el_GR.UTF8"; | |
190 | id="ATHENS"; | |
191 | print_dateline "$@"; | |
192 | ); line_sep; | |
193 | ||
194 | # Istanbul (pop. (2020): 13,719,061) | |
195 | ( | |
196 | export TZ=Asia/Istanbul; | |
197 | export LANG="tr_TR.UTF8"; | |
198 | id="ISTANBUL"; | |
199 | print_dateline "$@"; | |
200 | ); line_sep; | |
201 | ||
202 | # Tehran, Iran | |
203 | ( | |
204 | export TZ=Asia/Tehran; | |
205 | export LANG="fa_IR.UTF8"; | |
206 | id="TEHRAN"; | |
207 | print_dateline "$@"; | |
208 | ); line_sep; | |
209 | ||
210 | # Moscow, Russia | |
211 | ( | |
212 | export TZ=Europe/Moscow; | |
213 | export LANG="ru_RU.UTF-8"; | |
214 | id="MOSCOW"; | |
215 | print_dateline "$@"; | |
216 | ); line_sep; | |
217 | ||
218 | # Kyiv, Ukraine (pop. (2021): 2,962,180) | |
219 | ( | |
220 | export TZ=Europe/Kyiv; | |
221 | export LANG="uk_UA.UTF-8"; | |
222 | id="KYIV"; | |
223 | print_dateline "$@"; | |
224 | ); line_sep; | |
225 | ||
226 | # Delhi, India (pop. (2018): 29,000,000) | |
227 | ( | |
228 | export TZ=Asia/Kolkata; | |
229 | export LANG="hi_IN.UTF-8"; | |
230 | id="DELHI"; | |
231 | print_dateline "$@"; | |
232 | ); line_sep; | |
233 | ||
234 | # Jakarta, Indonesia (pop. (2018): 33,430,285) | |
235 | ( | |
236 | export TZ=Asia/Jakarta; | |
237 | export LANG="id_ID.UTF8"; | |
238 | id="JAKARTA"; | |
239 | print_dateline "$@"; | |
240 | ); line_sep; | |
241 | ||
242 | # Singapore, Singapore (pop (2018): 5,792,000) | |
243 | ( | |
244 | export TZ=Asia/Singapore; | |
245 | export LANG="en_SG.UTF-8"; | |
246 | id="SINGAPORE"; | |
247 | print_dateline "$@"; | |
248 | ); line_sep; | |
249 | ||
250 | # Beijing, China (pop. (2018): 19,618,000) | |
251 | ( | |
252 | export TZ=Asia/Shanghai; # [3] | |
253 | export LANG="zh_CN.UTF-8"; | |
254 | id="BEIJING"; | |
255 | print_dateline "$@"; | |
256 | ); line_sep; | |
257 | ||
20857531 SBS |
258 | # Taipei, Taiwan (pop (2019): 7,034,084) |
259 | ( | |
260 | export TZ=Asia/Taipei; # [3] | |
261 | export LANG="zh_TW.UTF-8"; | |
262 | id="TAIPEI"; | |
263 | print_dateline "$@"; | |
264 | ); line_sep; | |
265 | ||
4143a6ea SBS |
266 | # Tokyo, Japan (pop. (2018): 37,274,000) |
267 | ( | |
268 | export TZ=Asia/Tokyo; | |
269 | export LANG="ja_JP.UTF8"; | |
270 | id="TOKYO"; | |
271 | print_dateline "$@"; | |
272 | ); line_sep; | |
273 | ||
274 | # Seoul, South Korea (pop. (2018): 25,514,000) | |
275 | ( | |
276 | export TZ=Asia/Seoul; | |
277 | export LANG="ko_KR.UTF8"; | |
278 | id="SEOUL"; | |
279 | print_dateline "$@"; | |
280 | ); line_sep; | |
281 | ||
20857531 SBS |
282 | # Pyongyang, North Korea |
283 | ( | |
284 | export TZ=Asia/Pyongyang; | |
285 | export LANG="ko_KP.UTF8"; | |
286 | id="PYONGYANG"; | |
287 | print_dateline "$@"; | |
288 | ); line_sep; | |
289 | ||
4143a6ea SBS |
290 | # Sydney, Australia |
291 | ( | |
292 | export TZ=Australia/Sydney; | |
293 | export LANG="en_AU.UTF8"; | |
294 | id="SYDNEY"; | |
295 | print_dateline "$@"; | |
296 | ); line_sep; | |
297 | ||
298 | # Guam | |
299 | ( | |
300 | export TZ=Pacific/Guam; | |
301 | export LANG="en_GU.UTF8"; | |
302 | id="GUAM"; | |
303 | print_dateline "$@"; | |
304 | ); line_sep; | |
305 | ||
306 | # Auckland, New Zealand | |
307 | ( | |
308 | export TZ=Pacific/Auckland; | |
309 | export LANG="en_NZ.UTF8"; | |
310 | id="AUCKLAND"; | |
311 | print_dateline "$@"; | |
312 | ); line_sep; | |
313 | ||
314 | return 0; | |
315 | }; # main program | |
316 | ||
317 | main "$@"; |