SetClock

(Engine-Level Function)

Description: Sets the VTScada system clock and calendar.
Returns: Nothing
Usage: Script Only.
Function Groups: Time and Date
Related to: Seconds | Today
Format: SetClock(Date, Time)
Parameters:  
Date
Required. Any numeric expression giving the new date, in days since 1 January 1970.
Time
Required. Any numeric expression giving the new time, in seconds since midnight.
Comments:

This statement allows the synchronization of the VTScada system clock / calendar with another clock / calendar. All pending timers, and all built-in statements and functions that depend on the system clock / calendar are adjusted to match.

 

This function can work only when VTScada is run with administrative privileges. (Specifically, under a Windows user with the SE_SYSTEMTIME_NAME privilege.)

 

Caution is necessary, because VTScada will not adjust times and dates stored in variables or files (VTScada does not know if a variable contains a number or time or date). I/O drivers which time and date stamp results will not adjust themselves retroactively. However, as each new action occurs, the new time and date will be used. This is because I/O drivers are not built-in functions, they are modules.

Example:

If ZEditField(10, 40, 110, 10, minPastHr, 2, 1, 1);
[
  currTime = Seconds();
  minPastHr = Cast(minPastHr, 0){ Type status (0 - 255) };
  minPastHr %= 60 { Valid range is from 0 - 60 };
  convTime = currTime { Seconds since midnight }
  - currTime % 24 { Seconds past the hour }
  + (minPastHr * 60){ New seconds past the hour };
  SetClock(Today(), convTime) { Set the system clock };
]

This takes a value that has been entered into an input field and sets the system clock by it. The date and hour remain unchanged, only the minutes are set.