# LGF_SetTime (FB / V3.0.2)

Author: Siemens Digital Industry

## Short description

This block combines the functions of system time, local time, and set time zone.

### Block Interface

| LGF_SetTime (FB) |
--- | --- | ---
Bool |  |  | execute |  | done |  |  | Bool
DTL |  |  | systemTime |  | busy |  |  | Bool
Bool |  |  | isLocalTime |  | error |  |  | Bool
Int |  |  | timeZone |  | lastSetTimeZone |  |  | String
Bool |  |  | isDaylightSavingTime |  | status |  |  | Word
|  |  |  |  | subFunctionStatus |  |  | Word

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
execute | Bool | FALSE | Rising edge starts action once
systemTime | DTL | --- | System time to be set in PLC
isLocalTime | Bool | FALSE | TRUE: `systemTime` is local time, FALSE: `systemTime` is UTC time
timeZone | Int | 0 | Timezones HHMM [-1200.. -330.. 0.. 930.. 1200.. 1300]
isDaylightSavingTime | Bool | FALSE | Daylight saving time changeover, TRUE: activated, FALSE: deactivated (more infos at "Adjusting parameters in the `statTimeZone` variable")

### Output parameter

Identifier | Data type | Description
--- | --- | ---
done | Bool | TRUE: Commanded functionality has been completed successfully
busy | Bool | TRUE: FB is active and new output values can be expected
error | Bool | FALSE: No error / TRUE: An error occurred during the execution of the FB
lastSetTimeZone | String | Time zone that was set last by this block
status | Word | 16#0000-16#7FFF: Status of the FB / 16#8000-16#FFFF: Error identification (see following Table)
subFunctionStatus | Word | Status or return value of called FB's, FC's and system blocks

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_EXECUTION_FINISHED_NO_ERROR Execution finished without errors
16#7000 | STATUS_NO_CALL No job being currently processed
16#7001 | STATUS_FIRST_CALL First call after incoming new job (rising edge 'execute')
16#7002 | STATUS_SUBSEQUENT_CALL Subsequent call during active processing without further details
16#8201 | ERR_SET_TIME_LOCAL Error instruction WR_LOC_T: Write local time, check `subFunctionStatus` code
16#8202 | ERR_SET_TIME_UTC Error instruction WR_SYS_T: Set time-of-day, check `subFunctionStatus` code
16#8203 | ERR_SET_TIMEZONE Error instruction SET_TIMEZONE, check subFunctionStatus code
16#8600 | ERR_UNDEFINED_STATE Error due to an undefined state in state machine
16#8601 | ERR_WRONG_TIMEZONE Error due to an undefined time zone

## Functional description

NOTE
  The status of called commands is output in `subFunctionStatus`. In this case, the output value in `status` indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

This block combines the functions of system time, local time, and set time zone.

The following time zones are possible on the `timeZone` input:

Input `timeZone` | Time zone
--- | ---
-1200 | (UTC -12:00) Eniwetok, Kwajalein
-1100 | (UTC -11:00) Midway Island
-1000 | (UTC -10:00) Hawaii
-930 | (UTC -09:30) (French) Polynesia
-900 | (UTC -09:00) Alaska
-800 | (UTC -08:00) Tijuana, Los Angeles, Seattle, Vancouver
-700 | (UTC -07:00) Arizona, Denver, Salt Lake City, Calgary
-600 | (UTC -06:00) Chicago, Dallas, Kansas City, Winnipeg
-500 | (UTC -05:00) Eastern Time (USA & Canada)
-400 | (UTC -04:00) La Paz, Georgetown
-330 | (UTC -03:30) Newfoundland
-300 | (UTC -03:00) Brasilia, Buenos Aires
-200 | (UTC -02:00) Mid-Atlantic
-100 | (UTC -01:00) Azores, Cape Verde Is.
0 | (UTC) Dublin, Edinburgh, Lisbon, London
100 | (UTC +01:00) Berlin, Bern, Brussels, Rome, Stockholm, Vienna
200 | (UTC +02:00) Athens, Istanbul, Minsk, Bucharest
300 | (UTC +03:00) Moscow, St. Petersburg, Baghdad, Kuwait, Riyadh
330 | (UTC +03:30) Iran: Tehran
400 | (UTC +04:00) Abu Dhabi, Muscat
430 | (UTC +04:30) Afghanistan: Kabul
500 | (UTC +05:00) Islamabad, Karachi, Tashkent
530 | (UTC +05:30) India, Sri Lanka
545 | (UTC +05:45) Nepal
600 | (UTC +06:00) Astana, Almaty, Dhaka, Colombo
630 | (UTC +06:30) Coco Island, Myanmar
700 | (UTC +07:00) Bangkok, Hanoi, Jakarta
800 | (UTC +08:00) Beijing, Chongqing, Hong Kong, Urumqi
830 | (UTC +08:30) North Korea old
845 | (UTC +08:45) Western Australia: Eucla
900 | (UTC +09:00) Yakutsk, Osaka, Sapporo, Tokyo, Seoul
930 | (UTC +09:30) Australia: Northern Territory, South Australia
1000 | (UTC +10:00) Brisbane, Canberra, Melbourne, Sydney
1030 | (UTC +10:30) Australia: Lord Howe Island
1100 | (UTC +11:00) Vladivostok, Magadan, Solomon Is., New Caledonia
1200 | (UTC +12:00) Auckland, Wellington
1245 | (UTC +12:45) Chatham Islands
1300 | (UTC +13:00) Tonga, Samoa
1400 | (UTC +14:00) Kiribati

Note
  Daylight saving time/standard time
  The parameters (time difference, start summer time, start winter time) must be adapted to the desired time zone in the static variable `statTimeZone`.

####### Adjusting parameters in the `statTimeZone` variable

The static variable `statTimeZone` in the block interface is of the system data type TimeTransformationRule. In this system data type, the parameters for the local time zone and the summer/winter time changeover are stored.

The default values of the static variable `statTimeZone` are set to Central European Summer Time in the block interface:

- Time difference: 60 min
- Start summer time: last Sunday in March, 02:00 a.m.
- Start winter time: last Sunday in October, 03:00 a.m.

The following Figure shows the settings for the summer/winter time changeover of Central European Summer Time.

The parameter `Bias` is determined by the input parameter `timeZone`. The parameter `DaylightBias` depends on the input parameter `daylightSavingTime` and is either `0` or `60`.

For other time zones, the parameters for summer/winter time changeover must be adjusted (marked below).

## Change log

Version & Date | Change description
--- | ---
| 01.00.00 | Siemens Industry Online Support
| 08.06.2015 | First released version
| 01.00.01 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA V14 Update 1
| 01.00.02 | Siemens Industry Online Support
| 02.03.2017 | Bugfix: FB number: automatic
| 01.00.03 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 01.00.04 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 01.00.05 | Siemens Industry Online Support
| 20.02.2019 | Bugfix: Rising edge at input REQ of SET_TIMEOUT
| 01.00.06 | Simatic Systems Support
| 23.08.2019 | Reworked interface to PLC Open "execute" behavior Magic numbers removed, tag naming added, code reworked
| 03.00.00 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 03.00.02 | Simatic Systems Support
| 13.01.2020 | Bug fix - bias correction for time offsets (200 / 330) Insert documentation