Back

Topic

[KB847]Formatting the display of a register as a time and/or date

Tags: Animations, Variables

8 years ago
By RM
Options
Print
Applies to:

PcVue 10.0 onwards


Summary:

When formatting the display of a register as a time and/or date there are some subtleties in behaviour that are not immediately obvious. The following notes and attached project attempt to clarify these behaviours.

Formatting the display of a register as a time and/or date is explained in the Help:
Developing the HMI / Animation / Using custom display formats / Time and date formatting characters
This article should be used in conjunction with that topic which has details of the available formatting characters.

The formatting can be used in the Text-Display Register and Send-Register animations.

Originator: STFA / RM


Behaviors:

  1. The output is calculated starting with the largest time unit, the remainder from that is passed to the next largest time unit and so on.
    For example a format of hh:nn:ss@s with an input of 12959 (seconds).
    The hour is 12559/3600 = 3 r 1759
    The minute is 1759/60 = 29 r 19
    The seconds is 19
    So the output is 03:29:19
  2. When formatting as a time and / or date (as opposed to a period – see below) a modulus is applied to constrain the range to that expected of the unit.
    For example for a format of nn@n
    An input of 59 would display 59
    But an input of 61 would display 1
  3. When formatting as a time and / or date the output range is as you would expect for the unit.
    For example a month can only be 1 to 12 so a format of mm@d (month with input as day) produces 01 when the received unit value is 0.
  4. When formatting as a date the year is 1970 for an input of 0.
  5. When formatting as a time the hour calculation takes into account the time zone.
    For example hh@h and the time zone is UTC+1
    An input of 0 will display 1
    An input of 1 will display 2
    An input of 23 will display 0
Using the formatting characters as a period:If you enclose any of the formatting characters in square brackets their behaviour is modified and they behave as a period rather than a time and / or date.

  1. The formatting characters no longer represent a specific hour, month, year etc. but a number of hours, months, years. Hence the range is no longer limited by a modulus and the value for an input of 0 is 0.
  2. The hour no longer takes into account the time zone.
Inputting a time when in a time zone other that UTC0:If you use hh:nn:ss@s-hh:nn:ss in a time zone other than UTC0 you will find that it is not possible to enter an hour lower than the time offset. For example for UTC+1 the minimum time you can enter is 01:00:00.

The solution is to format the hour as a period. [hh]:nn:ss@s-[hh]:nn:ss.

If you want to prevent the User from entering a time greater than 23:59:59 (remember the hour is no longer constrained 0 to 23) you can do this using the Maximum property of the variable. In the above example, where the received unit is seconds, the Maximum would need to be set to 86399.

Download attachments: format.zip


Created on: 10 Nov 2016 Last update: 13 May 2024