Skip to content

Instantly share code, notes, and snippets.

@benob
Last active March 21, 2024 15:59
Show Gist options
  • Save benob/cb71f72f7348aab0f351cc46d10b59d6 to your computer and use it in GitHub Desktop.
Save benob/cb71f72f7348aab0f351cc46d10b59d6 to your computer and use it in GitHub Desktop.

Revisions

  1. benob revised this gist Mar 21, 2024. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions convert_time.sh
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,11 @@ ref=$1

    # fill this list with timezones you are interested in; first element is reference timezone
    zones[1]=`cat /etc/timezone`
    zones[2]="Asia/Calcutta"
    zones[3]="Asia/Tokyo"
    zones[4]="Australia/Brisbane"
    zones[5]="America/Montreal"
    zones[2]="Europe/London"
    zones[3]="Asia/Calcutta"
    zones[4]="Asia/Tokyo"
    zones[5]="America/Los_Angeles"
    zones[6]="America/Montreal"

    date -d "$ref" +'%a %D (%Z %:z)'
    for zone in "${zones[@]}"; do
  2. benob renamed this gist Mar 21, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions converted_times.sh → convert_time.sh
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,9 @@ zones[5]="America/Montreal"

    date -d "$ref" +'%a %D (%Z %:z)'
    for zone in "${zones[@]}"; do
    printf "%-20s " $zone
    # show converted time for timeslots from 8am to 7pm
    for time in `seq 8 19`; do
    printf "%-11s" `echo $zone|sed 's/.*\///;s/.*\(.\{10\}\)/…\1/'`
    # show converted time for timeslots from 8am to 5pm
    for time in `seq 8 17`; do
    echo -n " "$(TZ=$zone date -d "TZ=\"${zones[1]}\" $ref $time:00" +%H:%M)
    done
    # compute and show difference with local timezone
  3. benob created this gist Mar 21, 2024.
    27 changes: 27 additions & 0 deletions converted_times.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/bash

    # pass date as argument, empty is today
    ref=$1

    # fill this list with timezones you are interested in; first element is reference timezone
    zones[1]=`cat /etc/timezone`
    zones[2]="Asia/Calcutta"
    zones[3]="Asia/Tokyo"
    zones[4]="Australia/Brisbane"
    zones[5]="America/Montreal"

    date -d "$ref" +'%a %D (%Z %:z)'
    for zone in "${zones[@]}"; do
    printf "%-20s " $zone
    # show converted time for timeslots from 8am to 7pm
    for time in `seq 8 19`; do
    echo -n " "$(TZ=$zone date -d "TZ=\"${zones[1]}\" $ref $time:00" +%H:%M)
    done
    # compute and show difference with local timezone
    diff=$(expr $(printf "%g" `TZ=$zone date +%z`) - $(printf "%g" `date +%z`)|sed 's/..$/:&/;s/^/+/;s/^+-/-/')
    if [ "$diff" != +0 ]; then
    echo " ($diff)"
    else
    echo
    fi
    done