F_TranslateFileTimeBias

F_TranslateFileTimeBias 1:

This function converts the input time to the time in another time zone based on the specified bias time shift. The function can be used to convert the local time to UTC time (Universal Time Coordinates) and vice versa, for example.

FUNCTION F_TranslateFileTimeBias: T_FILETIME

T_FILETIME

VAR_INPUT

VAR_INPUT
    in      : T_FILETIME;(* Input time in file time format to be translated *)
    bias    : DINT;(* Bias value in minutes. The bias is the difference, in minutes, between Coordinated Universal Time (UTC) and local time. *)
    toUTC   : BOOL;(* TRUE => Translate from local time to UTC, FALSE => Translate from UTC to local Time *)
END_VAR

in: input time that is to be converted.

bias: difference between UTC time and local time in minutes (positive or negative values are permitted).

toUTC: this parameter can be used to specify the direction in which the input time is to be converted.

toUTC

Direction

Internal formula

FALSE

UTC -> local time

Local time := UTC - bias

TRUE

Local time -> UTC

UTC := local time + bias

 

Sample:

The in variable contains the time to be converted. The bToUTC variable determines the conversion direction. If bToUTC = TRUE, the local time is converted to UTC time, if bToUTC = FALSE, the UTC time is converted to local time. The WEST_EUROPE_TZI constant contains the time zone information for Western Europe. The required bias value is calculated from the time zone information in the constant and the current bDST setting (Daylight Saving Time). Alternatively, the current time zone information of a TwinCAT system can be determined with the function block:  FB_GetTimeZoneInformation.

F_TranslateFileTimeBias 2:

Data type DT was selected for the input time because of the visual control option in online mode. Conversions to other time formats are not necessarily recommend since the conversion functions can be very computing-intensive.

PROGRAM MAIN
VAR
    bDST    : BOOL := TRUE;(* TRUE => Daylight saving time, FALSE => Standard time *)
    bToUTC  : BOOL := FALSE;(* TRUE => Convert local time to UTC time, FALSE => Convert UTC time to local time *)
    in      : DT := DT#2011-08-29-15:15:31;
    out     : DT;
    bias    : DINT;
END_VAR
IF bDST THEN
    bias := WEST_EUROPE_TZI.bias + WEST_EUROPE_TZI.daylightBias;
ELSE
    bias := WEST_EUROPE_TZI.bias + WEST_EUROPE_TZI.standardBias;
END_IF

out := FILETIME_TO_DT( F_TranslateFileTimeBias( DT_TO_FILETIME( in ), bias, bToUTC ) );

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