How Can We Help?
How to automatically manage daylight saving time in the HMI using a macro?
In this post, we will show you how to automatically manage daylight saving time in the HMI using a macro. The time change was first applied in 1916. Since 2002, the time change has been carried out in a uniform manner in all the Member States of the European Union:
- the changeover to summer time takes place on the night of the last Saturday in March
- the changeover to winter time takes place on the night of the last Saturday in October
As a reminder, the EU countries are currently divided into three time zones:
- Western Europe (GMT): Ireland and Portugal
- Central Europe (GMT+1): Austria, Belgium, Croatia, Czech Republic, Denmark, France, Germany, Hungary, Italy, Luxembourg, Malta, Netherlands, Poland, Slovakia, Slovenia, Spain and Sweden
- Eastern Europe (GMT+2): Bulgaria, Cyprus, Estonia, Finland, Greece, Latvia, Lithuania and Romania.
With HMI-Tool
In the Macro Editor, add a new macro and copy it. #include "MacroInit.h"
Add the macro in “global Macro” list And set its execution frequency to 60000 ms (1 minute) to update the clock every minute.
void Macro_main(IN *p)
{
MarcoInit
// Daylight / Time change Summer Winter
// < ! > Call this script every minute
// The changeover to summer time takes place on the night of the last Saturday in March;
// the changeover to winter time takes place on the night of the last Saturday to Sunday in October.
int minute=BCD2BIN(LocalWord[60001]); // All are in BCD format. Convert in decimal.
int hour=BCD2BIN(LocalWord[60002]);
int day=BCD2BIN(LocalWord[60003]);
int month=BCD2BIN(LocalWord[60004]);
int dateofweek=BCD2BIN(LocalWord[60006]); // Monday=1
// The changeover to SUMMER time takes place on the night of the last Saturday in March. Sunday morning at 03:00:xx am, it's 04:00:xx am
if ((month==3) && (day>=25) && (dateofweek==7) && (hour==03) && (minute==00)) // March & 25th or more & Sunday & 03:00 pm ?
{
LocalWord[60002]=4; // New hour
LocalBit[65535]=0; // False=Summer time. (Necessary only for winter time)
}
// The changeover to WINTER time takes place on the night of the last Saturday to Sunday in October. Sunday morning at 03:00:xx am, it's 02:00:xx am
if ((LocalBit[65535]==0) && (month==10) && (day>=25) && (dateofweek==7) && (hour==03) && (minute==00)) // October & 25th or more & Sunday & 03:00 pm ?
{
LocalWord[60002]=2; // New hour
LocalBit[65535]=1; // True=Winter. Avoid a loop with an infinite change at every 3am because at 3am, it is 2am!
}
}
How it works
For daylight saving time, the last Sunday of March, between 03:00:00 and 03:00:59, the script will change the time to 04:00:xx. The seconds will not change.
For winter time, the last Sunday of October, between 03:00:00 and 03:00:59, the script will change the time to 02:00:xx. The seconds will not change.
In the Bit LB65535 you have the state of this daylight saving time: Winter=1, Summer=0.
You can replace LB65535 by LB51999 for backup the value (HMI register types: LB, LW, RWI and retentive/save register)
You can download here the HMI-Tool project (V7.0) if you wish to test it.
See also How to set and synchronize the ACE PLC clock with the HMI using a macro