-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor spydate to make it work better
- Loading branch information
Johannes Martinsson
committed
Mar 16, 2016
1 parent
b6a8a9c
commit affe46c
Showing
1 changed file
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
#!/bin/sh | ||
|
||
TIMESPEC=seconds | ||
ST=`TZ=Europe/Stockholm date --rfc-3339=$TIMESPEC` | ||
LK=`TZ=Asia/Sri_Lanka date --rfc-3339=$TIMESPEC` | ||
GH=`TZ=Africa/Ghana date --rfc-3339=$TIMESPEC` | ||
BD=`TZ=BST date --rfc-3339=$TIMESPEC` | ||
UT=`TZ=UTC date -u --rfc-3339=$TIMESPEC` | ||
|
||
echo " Ghana $GH" | ||
echo " Stockholm $ST" | ||
echo " Sri Lanka $LK" | ||
echo " Bangladesh $BD" | ||
echo " UTC $UT" | ||
#!/bin/zsh -f | ||
|
||
main() { | ||
set -A spytimes | ||
|
||
spytimes+=("Los Angeles" "America/Los_Angeles") | ||
spytimes+=("New York" "America/New_York") | ||
spytimes+=("UTC" "C") | ||
spytimes+=("Ghana" "Africa/Accra") | ||
spytimes+=("Nigeria" "Africa/Lagos") | ||
spytimes+=("Stockholm" "Europe/Stockholm") | ||
spytimes+=("Sri Lanka" "Asia/Colombo") | ||
spytimes+=("Bangalore" "Asia/Kolkata") | ||
spytimes+=("Bangladesh" "Asia/Dhaka") | ||
|
||
local longest=0 | ||
|
||
# Find the longest name so that we can align time output nicely. | ||
for name t in $spytimes; do | ||
if [[ $longest -lt ${#name} ]]; then | ||
longest=${#name} | ||
fi | ||
done | ||
|
||
for name t in $spytimes; do | ||
case $name in | ||
UTC) decorate=1 ;; | ||
*) decorate=0 ;; | ||
esac | ||
|
||
local attr="" | ||
|
||
[[ $decorate -eq 1 ]] && echo -n "\x1b[1m" | ||
printf "%${longest}s %s\n" "$name" "$(TZ=$t date --rfc-2822)" | ||
[[ $decorate -eq 1 ]] && echo -n "\x1b[0m" | ||
done | ||
} | ||
|
||
main |