Skip to content

Instantly share code, notes, and snippets.

@DosAmp
Created July 22, 2011 15:06
Show Gist options
  • Save DosAmp/1099630 to your computer and use it in GitHub Desktop.
Save DosAmp/1099630 to your computer and use it in GitHub Desktop.
Central European Timezone snippet for times when you have no control over /etc/TZ or /etc/timezone
cetz() {
LANG=C
# current year
YEAR=`date +%Y`
# current time stamp
NOW=`date +%s`
# transition day for Central European Summer Time
LAST_SUNDAY_OF_MARCH=`cal 3 $YEAR | sed '/^$/d' | tail -n 1 | cut -d ' ' -f 1`
# transition day for Central European Time
LAST_SUNDAY_OF_OCTOBER=`cal 10 $YEAR | sed '/^$/d' | tail -n 1 | cut -d ' ' -f 1`
# time stamp of summer time transition
CEST_TRANSITION=`date -d "${YEAR}-03-$LAST_SUNDAY_OF_MARCH 01:00:00 UTC" +%s`
## for *BSD
##CEST_TRANSITION=`date -ju ${YEAR}03${LAST_SUNDAY_OF_MARCH}0100.00 +%s`
# time stamp of winter time transition
CET_TRANSITION=`date -d "${YEAR}-10-$LAST_SUNDAY_OF_OCTOBER 01:00:00 UTC" +%s`
## for *BSD
##CET_TRANSITION=`date -ju ${YEAR}10${LAST_SUNDAY_OF_OCTOBER}0100.00 +%s`
if [ $NOW -lt $CEST_TRANSITION ] || [ $NOW -ge $CET_TRANSITION ]; then
# winter time
echo CET-1 | tee $HOME/.tz
else
# summer time
echo CEST-2 | tee $HOME/.tz
fi
}
##example usage in ~/.profile:
##TZ=`cetz`; export TZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment