TimeInterval

From HEWIKI
(Redirected from Time Interval)
Jump to: navigation, search

Contents

TimeInterval is a fundamental data type for fields and variables.

Overview

This page assumes that you have already familiarized yourself with information found on the DateTime page.

HSL provides for variables that represent a span of time through the TimeInterval data type. This helps implementers avoid issues of using integers that count the number of seconds (or milliseconds) that have passed since some well-defined start date. In conjunction with the TimeInterval data type, HSL also has a DateTime data type that represents a discreet moment in time.

Usage

The most common use of a TimeInterval is setting the fireRate of a timer field. This is usually done using using a literal TimeInterval in the form hh:mm:ss.sss. So if I have a node with a timer that I want to fire in 3 hours and 30 minutes I would do something like:

myNode.myTimer.fireRate = 03:30:00

The second most common use of a TimeInterval is calculating time that has elapsed since some timestamp was stored. This is done by subtracting one DateTime value from another:

elapsedTime as TimeInterval = SYSTEM.TIME.NOW - myNode.timestamp

Finally, there are four external functions that can be used to convert other data type into a TimeInterval. These are fairly self-explanatory.

To convert an integer that represents some period of time counted in milliseconds (0.001 of a second) to a TimeInterval:

elapsedTime as TimeInterval = TimeInMilliseconds( yourInteger )

To convert a float that represents some period of time measured in seconds to a TimeInterval:

elapsedTime as TimeInterval = TimeInSeconds( yourFloat )

To convert a float that represents some period of time measured in minutes to a TimeInterval:

elapsedTime as TimeInterval = TimeInMinutes( yourFloat )

To convert a float that represents some period of time measured in hours to a TimeInterval:

elapsedTime as TimeInterval = TimeInHours( yourFloat )

Subfields

A TimeInterval has four subfields that may be accessed via dot notation., allowing for easy conversion of its value to other data types:

millisecondsTotal as Integer
secondsTotal as Float
minutesTotal as Float
hoursTotal as Float

Additionally a TimeInterval has four subfields that may be accessed via dot notation that allow access to its component value to other data types:

millisecondsPortion as Integer
secondsPortion as Integer
minutesPortion as Integer
hoursPortion as Integer

Readable literals

The literal value for a TimeInterval is expressed as hh:mm:ss.sss; this is mostly for readability issues. Technically it is not necessary to pad components with a leading zero, nor is specifying a zero fractional second. So 1:2:3 would be valid, if difficult to read. Dispensing with the zero fractional zero is okay though, making the proper readable example 01:02:03.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox