FB_FileTimeToTzSpecificLocalTime

FB_FileTimeToTzSpecificLocalTime 1:

The function block converts the UTC time (file time format) to local time (file time format), taking into account the specified time zone information. The function block FB_SystemTimeToTzSpecificLocalTime has similar functionality but uses a different time format (structured system time format).

The block is only suitable for conversion of continuous UTC timestamp information. The function block uses the time zone information to calculate the required time steps (daylight-saving/standard time changeover) in local time. Time steps in UTC input time are not permitted and lead to incorrect conversion. The reason: the block stores the last converted time internally, so that it can detect the B times (see below) from the UTC input time and the stored value when the local time is changed.

The block is associated with an action: A_Reset(). If this action is called the block outputs and the locally stored (last converted) time are reset to zero.

 

1. Graphic representation of the changeover from daylight-saving time to standard time (tzInfo = WEST_EUROPE_TZI ):

FB_FileTimeToTzSpecificLocalTime 2:

The UTC input time (green) is continuous. The local time (red) jumps back. The local time: 02h:59m:59s:999ms.. is directly followed by: 02h:00m:00s:000ms.. The times between 2h and 3h occur twice. The duplicate time before the changeover is referred to as 02:05:00 CEST A , for example, the time after the changeover as 02:05:00 CET B. The output variable bB indicates whether it is the first or the second pass. During the second pass the bB output variable (blue) is set to TRUE. The bB output variable is automatically reset once the duplicate time has passed. The time zone ID (orange) changes from eTimeZoneID_Daylight (daylight-saving time) to eTimeZoneID_Standard (standard time).

 

2. Graphic representation of the change-over from standard time to daylight-saving time (tzInfo = WEST_EUROPE_TZI ):

FB_FileTimeToTzSpecificLocalTime 3:

The UTC input time (green) is continuous. The local time (green) jumps forward. The local time: 2h:59m:59s:999ms.. is directly followed by: 3h:00m:00s:000ms.. The time zone ID (orange) changes from eTimeZoneID_Standard (standard time) to eTimeZoneID_Daylight (daylight-saving time).

 

VAR_INPUT

VAR_INPUT
    in     : T_FILETIME;
    tzInfo : ST_TimeZoneInformation;
END_VAR

in: UTC time (file time format) to be converted.

tzInfo: Structure variable with the current time zone information of the operating system.

VAR_OUTPUT

VAR_OUTPUT
    out   : T_FILETIME;
    eTzID : E_TimeZoneID := eTimeZoneID_Unknown;
    bB    : BOOL;
END_VAR

out: Converted local time (file time format).

eTzID: Additional daylight-saving/standard time information.

bB: TRUE => B time (e.g.:02:05:00 CET B), FALSE => other time (e.g.: 02:05:00 CEST A). This output is set if the local time jumps back and is reset once the duplicate local time has passed.

 

Example:

The UTC time: DT#2011-09-02-09:01:31 is converted to local time. The result is: DT#2011-09-02-11:01:31.

PROGRAM MAIN
VAR
    in : DT := DT#2011-09-02-09:01:31;(* UTC time *)
    out : DT;(* Local time *)
    fbToLocal : FB_FileTimeToTzSpecificLocalTime;
END_VAR
fbToLocal( in := DT_TO_FILETIME( in ), tzInfo := WEST_EUROPE_TZI );
out := FILETIME_TO_DT( fbToLocal.out );

 

Further time and time zone functions and function blocks:

FB_TzSpecificLocalTimeToSystemTime, FB_TzSpecificLocalTimeToFileTime, FB_SystemTimeToTzSpecificLocalTime, FB_FileTimeTimeToTzSpecificLocalTime, FB_GetTimeZoneInformation, FB_SetTimeZoneInformation, NT_SetLocalTime, NT_GetTime, NT_SetTimeToRTCTime, F_TranslateFileTimeBias, FB_LocalSystemTime

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v2.11.0 Build > 2036

PC or CX (x86, ARM)

TcUtilities.Lib