#!/bin/bash

# wminfo plugin: displays time in different time zones

# command: wminfo -p conky.timezone.wmi -u 15 -b#000000 -f#ffff00

datafile="$HOME/.wminfo/conky.tmp"
label="TIMEZONE"

if [ -z "$(grep "^${label}: " "${datafile}")" ]
then
cat <<EOF
$0: no "${label}" entries were found in ${datafile} file.
         
         
         
         
EOF
    exit
fi

the_day_before_yesterday=`date --date="-2 days" +"%m-%d"`
yesterday=`date --date="yesterday" +"%m-%d"`
today=`date +"%m-%d"`
tomorrow=`date --date="tomorrow" +"%m-%d"`
the_day_after_tomorrow=`date --date="+2 days" +"%m-%d"`

grep "^${label}: " $datafile | sed -E "s/${label}: //;s/ /_/g" | \
while read timezone junk
do
    date=`echo $timezone | sed 's/.*_//'`
    if [ "$date" == "$the_day_before_yesterday" ]
    then
	echo "$timezone" | sed -E 's/^([A-Z][A-Z][A-Z])[A-Z]+./\1_/;s/([0-9])_/\1=_/;s/([A-Z])__/\1_/;s/_/ /g'
    elif [ "$date" == "$yesterday" ]
    then
	echo "$timezone" | sed -E 's/^([A-Z][A-Z][A-Z])[A-Z]+./\1_/;s/([0-9])_/\1-_/;s/([A-Z])__/\1_/;s/_/ /g'
    elif [ "$date" == "$today" ]
    then
	echo "$timezone" | sed -E 's/^([A-Z][A-Z][A-Z])[A-Z]+./\1_/;s/([0-9])_/\1__/;s/([A-Z])__/\1_/;s/_/ /g'
    elif [ "$date" == "$tomorrow" ]
    then
	echo "$timezone" | sed -E 's/^([A-Z][A-Z][A-Z])[A-Z]+./\1_/;s/([0-9])_/\1+_/;s/([A-Z])__/\1_/;s/_/ /g'
    elif [ "$date" == "$the_day_after_tomorrow" ]
    then
	echo "$timezone" | sed -E 's/^([A-Z][A-Z][A-Z])[A-Z]+./\1_/;s/([0-9])_/\1#_/;s/([A-Z])__/\1_/;s/_/ /g'
    fi
done

echo

