Table of Contents

IDateTime

Namespace
ZCore
INTERFACE IDateTime

Because a PLC might have multiple DateTime instances that are connected to different targets, DateTime objects are not implemented as singleton classes (i.e. a PRG). This Interface is implemented by datetime providers (e.g. DateTime, DateTimeUM) and can be used to make these function blocks available throughout the application by simply assigning these instances to a locally instantiated IDateTime.

Keep in mind that some of the methods that are available from this interface are only yielding meaningful outputs if the corresponding DateTime objects are done with their booting process, which may take several cyclics and can be checked by using the Synchronized property. The object that instanciates implementations of IDateTime is responsible to wait for the booting process of the implementation to finish.

Properties

Bias

PROPERTY Bias : LINT

This property returns the bias of the localtime to UTC in ms once DateTime is done with its booting process and thus, DateTime is in its Idle state. The bias is between localtime to UTC is defined as UTC = localtime + bias

Property Value

LINT

SynchronizationPeriod

PROPERTY SynchronizationPeriod : LREAL

Controls the period (in seconds) in which the current time is synchronized with reported by the operating system.

Property Value

LREAL

Synchronized

PROPERTY Synchronized : BOOL

This property returns TRUE if the object has a valid connection to a time syncing service, and the sync process has been successfully completed at least once. This usually occurs in the booting process and/or automatically after a period of time.

Property Value

BOOL

UtcOffset

PROPERTY UtcOffset : LINT

Returns the actual Utc Offset which gets retrieved from the local OS Timezone information

Property Value

LINT

Methods

CalendarInfo

METHOD CalendarInfo (
 [input] offset : LINT) : IDateTimeCalendarInfo

Returns an interface to a Calendar info data object represented by IDateTimeCalendarInfo based on the actual date shifted by a given utc-offset.

Inputs

offset LINT

utc offset in milliseconds

Returns

IDateTimeCalendarInfo

DeltaSecondsOs

METHOD DeltaSecondsOs (
 [input] unixTimestamp : ULINT) : LREAL

Returns the time difference now - unixTimestamp in seconds. The parameter unixTimestamp is usually previously stored from a call to UnixTimestamp. This method should be prefered to calls to DeltaSecondsPlc that uses PLC-Time timestamps in the local PLC context in contrast to this method. The PLC-Time timestamps can differ in resolution and starting point depending on your used PLC-system (e.g. TwinCAT, Ctrl-X,...)

Note

This method only returns valid information if the booting process of the object is finished, which can be checked with the State method.

Inputs

unixTimestamp ULINT

unix timestamp

Returns

LREAL

DeltaSecondsPlc

METHOD DeltaSecondsPlc (
 [input] filetime : ULINT) : LREAL

see DeltaSecondsOs

Inputs

filetime ULINT

unix timestamp

Returns

LREAL

Now

METHOD Now (
 [input] offset : LINT) : REFERENCE TO DateTimeRecord

Inputs

offset LINT

Returns

REFERENCE TO DateTimeRecord

TimestampLocalPlc

METHOD TimestampLocalPlc () : ULINT

Returns the current timestamp in the filetime format with 100ns resolution. This time may differ vastly from the time information that the operation system shows, because over time PLC time and OS time may drift appart. If the actual time information is more important than tick counts, UnixTimestamp method should be used which is returning a timestamp that is synchronized to OS time.

Returns

ULINT

UnixTimestamp

METHOD UnixTimestamp () : ULINT

Returns the actual timestamp in unix time format (beginning on 1.1.1970) cyclically corrected with the generated time lag between OS-time (which gets cyclically synced with the internet time) and the plc-runtime-time which gets just incremented over the CPU-Tick-Counter. The returned timestamp has a resolution of 1ms.

If the UnixTimestamp needs to be corrected via UTC-Offset, just add the value of UtcOffset to the return of this method.

Returns

ULINT