Daylight Saving Adjustment
I guess those of you on the emulator have NTP or some other way of correcting the time for Daylight Savings. I have only just found out that it is happening "tonight" and as I run mine standalone (no internet access) I have made an attempt to automate it using cron.
I have created a script called Daylight_Savings.sh whose code has been included below.
Code:
# ===========================
# Adjust for Daylight Savings
# ===========================
# Daylight Time commences at 2.00am Standard Time on the last
# Sunday in September each year. It ends at 2.00am Standard
# Time (3.00am Daylight Time) on the first Sunday in April of
# the following year.
#
# ===============
# Crontab Entries
# ===============
# Correct time for Daylight Saving
# 0 2 * 9 0 /var/hack/DST/DST_Adjust.sh >> /var/hack/DST/log 2>&1 &
# 0 3 * 4 0 /var/hack/DST/DST_Adjust.sh >> /var/hack/DST/log 2>&1 &
PATH=/bin:/sbin:/tvbin:/devbin:/var/hack/bin:/var/hack/scripts
StartDST() {
time=`date -d "now +1 hour" "+%Y%m%d%H%M%S"`
settime $time
}
StopDST() {
time=`date -d "now -1 hour" "+%Y%m%d%H%M%S"`
settime $time
}
date "+%w %e %b %k" |\
while read day dom mon hour; do
# Check if it is the last Sunday in September
if [ $dom -ge 22 -a $day -eq 0 -a "$mon" = "Sep" -a $hour -eq 2 ]; then
StartDST
fi
# Check if it is the first Sunday in April
if [ $dom -le 7 -a $day -eq 0 -a "$mon" = "Apr" -a $hour -eq 3 ]; then
StopDST
fi
done
The following is my crontab entry whose first line will trigger the script to run at 2am every Sunday during September... the script will check that it is the last Sunday before performing an action (sorry but this is a limitation of the cron scheduler). The second line will trigger the script to run at 3am every Sunday during April... the script will check that it is the first Sunday before performing an action.
Code:
# Correct time for Daylight Saving
0 2 * 9 0 /var/hack/DST/DST_Adjust.sh >> /var/hack/DST/log 2>&1 &
0 3 * 4 0 /var/hack/DST/DST_Adjust.sh >> /var/hack/DST/log 2>&1 &
Note: You may think that the script may loop in April as the time will be adjusted from 3am back to 2am... but the cron scheduler is smart enough to only run the script once (otherwise it would get stuck in a continuous one-hour loop).