Created
July 22, 2011 15:06
-
-
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
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
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