feat(user/bkdatev):Script to print various verbose iso-8601 dates
[BK-2020-03.git] / user / bkdatev
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.0.1
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
14 line_sep() {
15 # Input: var: n_ln
16 local skip_every=4;
17 ((n_ln++));
18 if ! ((n_ln % "$skip_every")); then
19 printf "\n";
20 fi;
21 return 0;
22 }; # periodically print separating blank line
23 print_dateline() {
24 # Input: var: $id
25 # var: $fs_1
26 # var: $fs_2
27 # var: $fs_3
28 # args: $@
29 # Output: stdout
30 # Depends: printf, date
31 # Ref/Attrib: * Truncate string in printf https://stackoverflow.com/a/46812677
32 local s_1 s_2 s_3 s_4;
33
34 s_1="$id";
35 s_2="$(date "$@" "$fs_1")";
36 s_3="$(date "$@" "$fs_2")";
37 s_4="$(date "$@" "$fs_3")";
38
39 printf "%-10.10s %-25.25s (%-20.20s) (%s)" "$s_1" "$s_2" "$s_3" "$s_4";
40 printf "\n";
41
42 unset fs_1 fs_2 fs_3 fs_4;
43 }; # print line of dates
44 main() {
45 n_ln=0; # for line_sep()
46
47 # format strings
48 fs_iso8601="+%Y-%m-%dT%H:%M:%S%:::z"; # typical ISO-8601
49 fs_iso8601_etc="+%G-W%V-%u, %Y-%j"; # alternate ISO-8601 dates
50 fs_locale="+%Z; %A; %c"; # locale-specific date strings
51
52 # vars for print_dateline()
53 fs_1="$fs_iso8601";
54 fs_2="$fs_iso8601_etc";
55 fs_3="$fs_locale";
56
57 # UTC (pop. (2021): 7,837,000,000)
58 (
59 export TZ=UTC;
60 id="UTC";
61 print_dateline "$@";
62 ); line_sep;
63
64 # Hawaii
65 (
66 export TZ=US/Hawaii;
67 export LANG="haw-US.UTF8";
68 id="HAWAII";
69 print_dateline "$@";
70 ); line_sep;
71
72 # Los Angeles, USA
73 (
74 export TZ=America/Los_Angeles;
75 export LANG="en_US.UTF-8";
76 id="LOS ANGELES";
77 print_dateline "$@";
78 ); line_sep;
79
80 # Denver, USA (pop. (2021): 711,463)
81 (
82 export TZ=America/Denver;
83 export LANG="en_US.UTF-8";
84 id="DENVER";
85 print_dateline "$@";
86 ); line_sep;
87
88 # Chicago, USA (pop. (2021): 711,463)
89 (
90 export TZ=America/Chicago;
91 export LANG="en_US.UTF-8";
92 id="CHICAGO";
93 print_dateline "$@";
94 ); line_sep;
95
96 # Mexico City, Mexico (pop. (2018): 21,804,515)
97 (
98 export TZ=America/Mexico_City;
99 export LANG="es_MX.UTF8";
100 id="MEXICO CITY";
101 print_dateline "$@";
102 ); line_sep;
103
104 # Panama City, Panama
105 (
106 export TZ=America/Panama;
107 export LANG="es_PA.UTF8";
108 id="PANAMA CITY";
109 print_dateline "$@";
110 ); line_sep;
111
112 # New York, USA (pop. (2018): 20,140,470)
113 (
114 export TZ=America/New_York;
115 export LANG="en_US.UTF-8";
116 id="NEW YORK";
117 print_dateline "$@";
118 ); line_sep;
119
120 # São Paulo, Brazil
121 (
122 export TZ=America/Sao_Paulo;
123 export LANG="pt_BR.UTF8";
124 id="SAO PAULO";
125 print_dateline "$@";
126 ); line_sep;
127
128 # Buenos Aires
129 (
130 export TZ=America/Argentina/Buenos_Aires;
131 export LANG="es_AR.UTF8";
132 id="BUENOS AIRES";
133 print_dateline "$@";
134 ); line_sep;
135
136 # London, England
137 (
138 export TZ=Europe/London;
139 export LANG="en_GB.UTF-8";
140 id="LONDON";
141 print_dateline "$@";
142 ); line_sep;
143
144 # Kinshasa, Africa
145 (
146 export TZ=Africa/Kinshasa;
147 export LANG="ln_CD.UTF8";
148 id="KINSHASA";
149 print_dateline "$@";
150 ); line_sep;
151
152 # Lagos, Africa
153 (
154 export TZ=Africa/Lagos;
155 export LANG="en_NG.UTF8";
156 id="LAGOS";
157 print_dateline "$@";
158 ); line_sep;
159
160 # Paris, France
161 (
162 export TZ=Europe/Paris;
163 export LANG="fr_FR.UTF8";
164 id="PARIS";
165 print_dateline "$@";
166 ); line_sep;
167
168 # Stockholm, Sweden
169 (
170 export TZ=Europe/Stockholm;
171 export LANG="sv_SE.UTF8";
172 id="STOCKHOLM";
173 print_dateline "$@";
174 ); line_sep;
175
176 # Cairo, Egypt
177 (
178 export TZ=Africa/Cairo;
179 export LANG="ar_EG.UTF8";
180 id="CAIRO";
181 print_dateline "$@";
182 ); line_sep;
183
184 # Athens (pop. (2020): 3,526,887)
185 (
186 export TZ=Europe/Athens;
187 export LANG="el_GR.UTF8";
188 id="ATHENS";
189 print_dateline "$@";
190 ); line_sep;
191
192 # Istanbul (pop. (2020): 13,719,061)
193 (
194 export TZ=Asia/Istanbul;
195 export LANG="tr_TR.UTF8";
196 id="ISTANBUL";
197 print_dateline "$@";
198 ); line_sep;
199
200 # Tehran, Iran
201 (
202 export TZ=Asia/Tehran;
203 export LANG="fa_IR.UTF8";
204 id="TEHRAN";
205 print_dateline "$@";
206 ); line_sep;
207
208 # Moscow, Russia
209 (
210 export TZ=Europe/Moscow;
211 export LANG="ru_RU.UTF-8";
212 id="MOSCOW";
213 print_dateline "$@";
214 ); line_sep;
215
216 # Kyiv, Ukraine (pop. (2021): 2,962,180)
217 (
218 export TZ=Europe/Kyiv;
219 export LANG="uk_UA.UTF-8";
220 id="KYIV";
221 print_dateline "$@";
222 ); line_sep;
223
224 # Delhi, India (pop. (2018): 29,000,000)
225 (
226 export TZ=Asia/Kolkata;
227 export LANG="hi_IN.UTF-8";
228 id="DELHI";
229 print_dateline "$@";
230 ); line_sep;
231
232 # Jakarta, Indonesia (pop. (2018): 33,430,285)
233 (
234 export TZ=Asia/Jakarta;
235 export LANG="id_ID.UTF8";
236 id="JAKARTA";
237 print_dateline "$@";
238 ); line_sep;
239
240 # Singapore, Singapore (pop (2018): 5,792,000)
241 (
242 export TZ=Asia/Singapore;
243 export LANG="en_SG.UTF-8";
244 id="SINGAPORE";
245 print_dateline "$@";
246 ); line_sep;
247
248 # Beijing, China (pop. (2018): 19,618,000)
249 (
250 export TZ=Asia/Shanghai; # [3]
251 export LANG="zh_CN.UTF-8";
252 id="BEIJING";
253 print_dateline "$@";
254 ); line_sep;
255
256 # Tokyo, Japan (pop. (2018): 37,274,000)
257 (
258 export TZ=Asia/Tokyo;
259 export LANG="ja_JP.UTF8";
260 id="TOKYO";
261 print_dateline "$@";
262 ); line_sep;
263
264 # Seoul, South Korea (pop. (2018): 25,514,000)
265 (
266 export TZ=Asia/Seoul;
267 export LANG="ko_KR.UTF8";
268 id="SEOUL";
269 print_dateline "$@";
270 ); line_sep;
271
272 # Sydney, Australia
273 (
274 export TZ=Australia/Sydney;
275 export LANG="en_AU.UTF8";
276 id="SYDNEY";
277 print_dateline "$@";
278 ); line_sep;
279
280 # Guam
281 (
282 export TZ=Pacific/Guam;
283 export LANG="en_GU.UTF8";
284 id="GUAM";
285 print_dateline "$@";
286 ); line_sep;
287
288 # Auckland, New Zealand
289 (
290 export TZ=Pacific/Auckland;
291 export LANG="en_NZ.UTF8";
292 id="AUCKLAND";
293 print_dateline "$@";
294 ); line_sep;
295
296 return 0;
297 }; # main program
298
299 main "$@";