View Single Post
  #1   (View Single Post)  
Old 18th March 2021
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default Batch Time Zone converter for Zoom meetings etc

Recently I wrote a script on Linux Mint to convert a date to multiple time zones. Primarily to assist a US Zoom meeting organizer deal with the summertime/Daylight Saving Time switches in March and April.

I just finished adapting it to OpenBSD because the BSD date program is quite different from the GNU date used in Linux.
The script could need some improvements, e.g. for specifying the date. GNU date is very flexible in the date/time parameters, while BSD date only allows a Spartan single format like 202101061500 for Jan 6th 15:00 2021.

The date March 10th 10:00 AM can be converted to Central European Time with the following command:
Code:
$ env TZ=America/New_York date -j -z Europe/Amsterdam 03101000
Wed Mar 10 16:00:00 CET 2021
Because time zone abbreviations are not unique, it is better to use the geo to zone mappings defined in the tz database at
Code:
$  ls -l /usr/share/zoneinfo/Europe | head
total 404
-r--r--r--  1 root  bin  2923 Mar 14 21:45 Amsterdam
-r--r--r--  1 root  bin  1725 Mar 14 21:45 Andorra
-r--r--r--  1 root  bin  1169 Mar 14 21:45 Astrakhan
-r--r--r--  1 root  bin  2245 Mar 14 21:45 Athens
-r--r--r--  7 root  bin  3661 Mar 14 21:45 Belfast
-r--r--r--  6 root  bin  1931 Mar 14 21:45 Belgrade
-r--r--r--  1 root  bin  2309 Mar 14 21:45 Berlin
-r--r--r--  2 root  bin  2312 Mar 14 21:45 Bratislava
-r--r--r--  1 root  bin  2944 Mar 14 21:45 Brussels
You can read more about this database at https://en.wikipedia.org/wiki/Tz_database

Converting March 10th 10:00 AM New York time, goes as follows:

Code:
$ ./batch_time_convert.sh  03101000 America/New_York

USA
Wed Mar 10 07:00 PST 2021 -0800 America/Los_Angeles
Wed Mar 10 08:00 MST 2021 -0700 America/Denver
Wed Mar 10 09:00 CST 2021 -0600 America/Chicago
Wed Mar 10 10:00 EST 2021 -0500 America/New_York

Canada
Wed Mar 10 07:00 PST 2021 -0800 America/Vancouver
Wed Mar 10 08:00 MST 2021 -0700 America/Edmonton
Wed Mar 10 09:00 CST 2021 -0600 America/Regina
Wed Mar 10 09:00 CST 2021 -0600 America/Winnipeg
Wed Mar 10 10:00 EST 2021 -0500 America/Montreal

Europe
Wed Mar 10 15:00 UTC 2021 +0000 UTC
Wed Mar 10 15:00 GMT 2021 +0000 Europe/Dublin
Wed Mar 10 15:00 GMT 2021 +0000 Europe/London
Wed Mar 10 16:00 CET 2021 +0100 Europe/Brussels
Wed Mar 10 17:00 EET 2021 +0200 Europe/Helsinki
Wed Mar 10 17:00 EET 2021 +0200 Europe/Riga
Wed Mar 10 18:00 MSK 2021 +0300 Europe/Moscow

Australia & New Zealand
Wed Mar 10 23:00 AWST 2021 +0800 Australia/Perth
Thu Mar 11 01:30 ACDT 2021 +1030 Australia/Adelaide
Thu Mar 11 02:00 AEDT 2021 +1100 Australia/Sydney
Thu Mar 11 04:00 NZDT 2021 +1300 Pacific/Auckland

Asia (Singapore,Taiwan, Japan)
Wed Mar 10 23:00 +08 2021 +0800 Asia/Singapore
Wed Mar 10 23:00 CST 2021 +0800 Asia/Taipei
Thu Mar 11 00:00 JST 2021 +0900 Asia/Tokyo
Four days later when USA has switched to Daylight Saving Time (DST), while Europe has not:
Code:
$ ./batch_time_convert.sh  03141000 America/New_York

USA
Sun Mar 14 07:00 PDT 2021 -0700 America/Los_Angeles
Sun Mar 14 08:00 MDT 2021 -0600 America/Denver
Sun Mar 14 09:00 CDT 2021 -0500 America/Chicago
Sun Mar 14 10:00 EDT 2021 -0400 America/New_York
[snip]
Europe
Sun Mar 14 14:00 UTC 2021 +0000 UTC
Sun Mar 14 14:00 GMT 2021 +0000 Europe/Dublin
Sun Mar 14 14:00 GMT 2021 +0000 Europe/London
Sun Mar 14 15:00 CET 2021 +0100 Europe/Brussels
Sun Mar 14 16:00 EET 2021 +0200 Europe/Helsinki
Sun Mar 14 16:00 EET 2021 +0200 Europe/Riga
Sun Mar 14 17:00 MSK 2021 +0300 Europe/Moscow
Those Down Under (yes, we mean you 'mate') switch from DST to standard time somewhere in April:

Code:
$ ./batch_time_convert.sh  04141000 America/New_York
[snip]
Wed Apr 14 10:00 EDT 2021 -0400 America/New_York
[snip]
Australia & New Zealand
Wed Apr 14 22:00 AWST 2021 +0800 Australia/Perth
Wed Apr 14 23:30 ACST 2021 +0930 Australia/Adelaide
Thu Apr 15 00:00 AEST 2021 +1000 Australia/Sydney
Thu Apr 15 02:00 NZST 2021 +1200 Pacific/Auckland
The date and zone mapping are specified on the command line, while the zones to be converted to, are specified in the script in sets of two editable variables:
Code:
HEADER_EUR="Europe"
ZONES_EUR="UTC Europe/Dublin Europe/London Europe/Brussels Europe/Helsinki Europe/Riga Europe/Moscow"
These are passed to a shell function that calls date(1) to do the conversion:
Code:
zone_convert "$HEADER_EUR"    "$ZONES_EUR"
zone_convert "$HEADER_AUS"    "$ZONES_AUS"
zone_convert "$HEADER_ASIA"   "$ZONES_ASIA"
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote