VAR_GLOBAL CONSTANT
( Eastern Timezone declaration for Toronto, Canada.
DST begins on 2nd Sunday in March and EST begins on 1st Sunday in November by 1 hour.
Note: Ontario has two timezones - Central & Eastern
uiDay => 1..5 1=> first day of the month, 5 => last day of the month )
( Set Eastern Timezone for Toronto, Canada - DST begins on 2nd Sunday in March and EST begins on 1st Sunday in November )
( Using FUNCTIONS: getTimeDate & localDateTime )
// UTC
utcDateTime := getDateTime();
SeparateDateTime(uliDateTIme:=utcDateTime,eWeekday=>utc_eWeekday,datDate=>utcDate,todTime=>utcTime);
utc_sWeekday := tzoneDOW(utc_eWeekday); // UTC Day of Week, 1= Mon, 2=TUE
tZone := (utcDateTime - localDT) / (1000 * 3600); // utc-local time difference in hours
local_sWeekday := tzoneDOW(local_eWeekday); // Local Time Day of Week, 1= Mon, 2=TUE
( LOCAL TIMEZONE INFO - for HMI display purposes only )
IF period = 1 THEN status := 'STANDARD'; dst := FALSE;
ELSIF period = 2 THEN status := 'DAYLIGHT'; dst := TRUE;
ELSE status := 'UNKNOWN'; dst := FALSE;
END_IF
That way your code snippet is neatly organized and availabe on a central definded location. We (the community) hope to see more of your contributions there.
PS. you can also use your HOME/Blog location for this or open a project in the projects section.
have π fun!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Codesys V3.5 SP17 Patch 3 (64bit)
Pi package: 4.2.0.0
PFC200 package: 4.2.0.0
Here's my scripts for implementing local timezone for Eastern Standard Time - Toronto Canada.
Using UTIL Functions - getDateTime() and localDateTime()
1 Install UTIL Library
Library Manager > Add Library > UTIL Library 3.5.17.0
2 Global Variable List
GLOBAL VARIABLE LIST
code
~~~
VAR_GLOBAL CONSTANT
( Eastern Timezone declaration for Toronto, Canada.
DST begins on 2nd Sunday in March and EST begins on 1st Sunday in November by 1 hour.
Note: Ontario has two timezones - Central & Eastern
uiDay => 1..5 1=> first day of the month, 5 => last day of the month )
END_VAR
3 POU: prgTimeZone
PROGRAM prgTimeZone
VAR
END_VAR
( Set Eastern Timezone for Toronto, Canada - DST begins on 2nd Sunday in March and EST begins on 1st Sunday in November )
( Using FUNCTIONS: getTimeDate & localDateTime )
// UTC
utcDateTime := getDateTime();
SeparateDateTime(uliDateTIme:=utcDateTime,eWeekday=>utc_eWeekday,datDate=>utcDate,todTime=>utcTime);
utc_sWeekday := tzoneDOW(utc_eWeekday); // UTC Day of Week, 1= Mon, 2=TUE
// EST/DST
localDT := localDateTime(tzTimeZone:=gvl.gc_tzTimeZoneTOR,uliDateTIme:=utcDateTime,eErrorID=>errorID,ePeriod=>period);
SeparateDateTime(uliDateTIme:=localDT,eWeekday=>local_eWeekday,datDate=>localDate,todTIme=>localTime);
tZone := (utcDateTime - localDT) / (1000 * 3600); // utc-local time difference in hours
local_sWeekday := tzoneDOW(local_eWeekday); // Local Time Day of Week, 1= Mon, 2=TUE
( LOCAL TIMEZONE INFO - for HMI display purposes only )
localTimezoneInfo.est_iBias := gvl.gc_tzTimeZoneTOR.iBias;
localTimezoneInfo.est_sName := gvl.gc_tzTimeZoneTOR.asgPeriod[1].sName;
localTimezoneInfo.est_month := gvl.gc_tzTimeZoneTOR.asgPeriod[1].dtDate.uiMonth;
localTimezoneInfo.est_eWeekday := gvl.gc_tzTimeZoneTOR.asgPeriod[1].dtDate.eWeekday;
localTimezoneInfo.est_sWeekday := tzoneDOW(gvl.gc_tzTimeZoneTOR.asgPeriod[1].dtDate.eWeekday); // Function(tzoneDOW)
localTimezoneInfo.est_day := gvl.gc_tzTimeZoneTOR.asgPeriod[1].dtDate.uiDay;
localTimezoneInfo.est_hour := gvl.gc_tzTimeZoneTOR.asgPeriod[1].dtDate.uiHour;
localTimezoneInfo.est_minute := gvl.gc_tzTimeZoneTOR.asgPeriod[1].dtDate.uiMinute;
localTimezoneInfo.dst_iBias := gvl.gc_tzTimeZoneTOR.asgPeriod[2].iBias;
localTimezoneInfo.dst_sName := gvl.gc_tzTimeZoneTOR.asgPeriod[2].sName;
localTimezoneInfo.dst_month := gvl.gc_tzTimeZoneTOR.asgPeriod[2].dtDate.uiMonth;
localTimezoneInfo.dst_eWeekday := gvl.gc_tzTimeZoneTOR.asgPeriod[2].dtDate.eWeekday;
localTimezoneInfo.dst_sWeekday := tzoneDOW(gvl.gc_tzTimeZoneTOR.asgPeriod[2].dtDate.eWeekday); // Function(tzoneDOW)
localTimezoneInfo.dst_day := gvl.gc_tzTimeZoneTOR.asgPeriod[2].dtDate.uiDay;
localTimezoneInfo.dst_hour := gvl.gc_tzTimeZoneTOR.asgPeriod[2].dtDate.uiHour;
localTimezoneInfo.dst_minute := gvl.gc_tzTimeZoneTOR.asgPeriod[2].dtDate.uiMinute;
IF period = 1 THEN status := 'STANDARD'; dst := FALSE;
ELSIF period = 2 THEN status := 'DAYLIGHT'; dst := TRUE;
ELSE status := 'UNKNOWN'; dst := FALSE;
END_IF
4 Datatype: TimeZoneInfo(STRUCT)
TYPE TimezoneInfo :
STRUCT
END_STRUCT
END_TYPE
5 Function: tzoneDOW
FUNCTION tzoneDOW : string
VAR_INPUT
eWeekday : UTIL.WEEKDAY;
END_VAR
VAR
END_VAR
( Local Timezone Day of Week )
CASE eWeekday OF
1 : tzoneDOW := 'MON';
2 : tzoneDOW := 'TUE';
3 : tzoneDOW := 'WED';
4 : tzoneDOW := 'THU';
5 : tzoneDOW := 'FRI';
6 : tzoneDOW := 'SAT';
7 : tzoneDOW := 'SUN';
END_CASE
6 HMI
see attachment
-krstech integration
Related
Talk.ru: 1
Talk.ru: 2
Last edit: krstech 2022-03-09
Attached snapshots for your reference.
-krstech
Last edit: krstech 2022-03-08
What exactly is your question βοΈππͺ
Do not have a question.
It is a working example
krstech
Last edit: krstech 2022-03-08
Hi, Any all contributions of code to Forge is fantastic but I feel that your cide nippets like this are best to be post here:
https://forge.codesys.com/tol/iec-snippets/snippets/
That way your code snippet is neatly organized and availabe on a central definded location. We (the community) hope to see more of your contributions there.
PS. you can also use your HOME/Blog location for this or open a project in the projects section.
have π fun!
Last edit: hermsen 2022-03-08