1

Im currently designing a solution to synchronize a Clock on a Equipment. Each time the Equipment is turned on after a poweroff, its Clock is exactly "01:01". To sync this Equipment, I have a NEXA remote switch and a Telldus duo. The Telldus duo is connected to a server which is a NTP server with GPS and PPS source.

Now to the problem: Currently, the Clock synchronizes by simply turning off Power scheduled at 01:00, and then turning on Power 01:01, causing the Clock on the Equipment to Always go correct.

But the problem is on DST change Days. If there is a DST change day that says the Clock should be moved FORWARD 1 hour at 02:00 to 03:00, then the Clock on the Equipment will be behind by 1 hour in one full day. If there is a DST change day that says the Clock should be moved BACK 1 hour, then the equpment will be running 1 hour too fast.

Thus, on the DST FORWARD Days, I need to Schedule the Equipment to turn off at 00:00 and turn on at 00:01. Then the Equipment will be 01:01 when Clock is 00:01. When Clock is 02:00 and is changed to 03:00, then Equipment will already be at 03:00, thus Equipment will only have incorrect Clock for 2 hour.

And on the DST BACK Days, I need to Schedule the Equipment to turn off at 02:00 and turn on at 02:01. Thus the Equipment will be 02:00 when Clock is 03:00 and being DST'ed back to 02:00, thus in this case Equipment's Clock will only be incorrect for 1 hour.


I have the full capatibility to write a script that will accomplish this, GIVEN THAT:

I know a command, that can tell me, if TODAY is the day that a DST change will occur, and in which direction (02:00 to 03:00, or 03:00 to 02:00) it will occur.

This means I need either some dedicated DST command, OR a possibility to "look in the future", like "What is the Clock when 4 hours have elapsed from now, accounting for DST?". (Then I could check, if the difference between now and returned clock is 3 hours, then its a DST-BACK day, 4 hours, then its a NO-DST day and 5 hours then its a DST-FORWARD day)

Anyone that have a idea of such command?

1

Try:

$ zdump -v Europe/London  -c $(date '+%Y'),$(date -d '+1 year' '+%Y') | awk -v y=$(date '+%Y') '$6==y && $15~1 {print $4, $3, $6}'
30 Mar 2014
26 Oct 2014

Which prints the dates at which DST changes. Change the Europe/London to your timezone.

Or, slightly longer:

$ zdump -v Europe/London  -c $(date '+%Y'),$(date -d '+1 year' '+%Y') | awk -v y=$(date '+%Y') '
                                     ($6==y && dst=="") {dst=$15}
                                     ($6==y && dst==$15) {ftime=$12; dst=$15;}
                                     ($6==y && dst!=$15) {print ftime, "to", $12, "on", $4, $3, $6, $15; dst=$15}'
00:59:59 to 02:00:00 on 30 Mar 2014 isdst=1
01:59:59 to 01:00:00 on 26 Oct 2014 isdst=0

Which prints the time changes too. The last column shows whether you are entering DST (1 means entering DST).

  • nice command! But took a pretty long time to execute. Adding -c $(date '+%Y'),$(date -d '+1 year' '+%Y') to the zdump command solved this problem. (had to read the zdump manual. Didnt even know Zdump existed) – sebastian nielsen Aug 30 '14 at 23:26
  • True - your changes brought it down from 0.7s to 0.01s for me. I'll edit my post. zdump manual? Mine doesn't have one :-( – garethTheRed Aug 31 '14 at 7:16
0

If anyone has come here via Google looking for a simple daylight savings detection command for the linux terminal, this suffices. This is not complex enough for OP's question however.

if perl -e 'exit ((localtime)[8])' ; then
    echo no DST
else
    echo DST
fi

*the 8th element in the output of localtime in perl is $isdst http://perldoc.perl.org/functions/localtime.html

0

I would just ask the system how it would print the time in exactly 24 hours:

now=$(date +%H)
then=$(date -d '24 hours' +%H)
dst_change=$(( then - now ))

Caution, don't run this on the hour sharp...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.