new RelTime()
Represents a baja:RelTime in BajaScript.
RelTime is a Simple type for managing a relative amount of time.
When creating a Simple, always use the make() method instead of
creating a new Object.
Extends
Members
-
<static> DAY :baja.RelTime
-
RelTimeinstance for a day.Type:
-
<static> DEFAULT :baja.RelTime
-
Default
RelTimeinstance.Type:
-
<static> HOUR :baja.RelTime
-
RelTimeinstance for an hour.Type:
-
<static> MILLIS_IN_DAY :Number
-
Milliseconds in a day.
Type:
- Number
-
<static> MILLIS_IN_HOUR :Number
-
Milliseconds in an hour.
Type:
- Number
-
<static> MILLIS_IN_MINUTE :Number
-
Milliseconds in a minute.
Type:
- Number
-
<static> MILLIS_IN_SECOND :Number
-
Milliseconds in a second.
Type:
- Number
-
<static> MINUTE :baja.RelTime
-
RelTimeinstance for a minute.Type:
-
<static> SECOND :baja.RelTime
-
RelTimeinstance for a second.Type:
Methods
-
<static> make( [obj])
-
Make a
RelTime.Parameters:
Name Type Argument Description objObject | Number <optional>
the Object Literal or the number of milliseconds.
Properties
Name Type Argument Description daysNumber <optional>
the number of days.
hoursNumber <optional>
the number of hours.
minutesNumber <optional>
the number of minutes.
secondsNumber <optional>
the number of seconds.
msNumber <optional>
the number of milliseconds.
Returns:
- Type
- baja.RelTime
Example
//This method can take a number of milliseconds or an Object Literal as //method's argument... var rt1 = baja.RelTime.make(1000); // One second // ...or we can specify an Object Literal for more arguments... // Create a RelTime with 2 days + 2 hours + 2 minutes + 2 seconds + 2 milliseconds... var rt2 = baja.RelTime.make({ days: 2, hours: 2, minutes: 2, seconds: 2, ms: 2 }); -
decodeAsync(str [, batch])
-
The string encoding of certain Simples may include Type information, or
other data that may be require asynchronous operations to decode. BOX is
designed to handle these situations when decoding data from the station,
but when user code needs to decode string-encoded Simples directly, prefer
this method as it gives the individual Simple a chance to import Types,
etc. to ensure that the decoded Simple is fully correct.The default implementation just returns
decodeFromStringdirectly.Parameters:
Name Type Argument Description strstring batchbaja.comm.Batch <optional>
optional batch to use
- Inherited From:
Returns:
may return the Simple instance
directly, or a Promise resolving to same - so wrap inPromise.resolve()
if unsure.- Type
- baja.Simple | Promise.<baja.Simple>
-
decodeFromString(str)
-
Decode a
RelTimefrom aString.Parameters:
Name Type Description strString - Overrides:
Returns:
- Type
- baja.RelTime
-
encodeToString()
-
Encode the
RelTimeto aString.- Overrides:
Returns:
- Type
- String
-
equals(obj)
-
Equality test.
Parameters:
Name Type Description obj- Overrides:
Returns:
- Type
- Boolean
-
equivalent(obj)
-
Equivalence test.
equivalent()is used to compare if two Objects have equivalent
state, but might not want to return true for equals since it
it has implied semantics for many operations. The default
implementation returns the result of baja.Object#equals.Parameters:
Name Type Description obj- Inherited From:
Returns:
- Type
- Boolean
-
getAgents( [is] [, batch])
-
Returns a promise that resolves to the agent list for this Object.
Parameters:
Name Type Argument Description isArray.<String> <optional>
An optional array of filters to add to the
agent query.batchbaja.comm.Batch <optional>
An optional object used to batch network
calls together.- Inherited From:
- See:
Returns:
A promise that will resolve with the Agent Info.
- Type
- Promise
-
getDataTypeSymbol()
-
Return the data type symbol.
Returns:
- Type
- String
-
getDays()
-
Return number of days.
Returns:
- Type
- Number
-
getDaysPart()
-
Return the days part of this duration.
Returns:
- Type
- Number
-
getHours()
-
Return number of hours.
Returns:
- Type
- Number
-
getHoursPart()
-
Return the hours part of this duration.
Returns:
- Type
- Number
-
getIcon()
-
Return the Object's Icon.
- Inherited From:
Returns:
- Type
- baja.Icon
-
getMillis()
-
Return number of milliseconds.
Returns:
- Type
- Number
-
getMillisPart()
-
Return the milliseconds part of this duration.
Returns:
- Type
- Number
-
getMinutes()
-
Return number of minutes.
Returns:
- Type
- Number
-
getMinutesPart()
-
Return the minutes part of this duration.
Returns:
- Type
- Number
-
getSeconds()
-
Return number of seconds.
Returns:
- Type
- Number
-
getSecondsPart()
-
Return the seconds part of this duration.
Returns:
- Type
- Number
-
getType()
-
Get the type of this instance.
- Inherited From:
Returns:
- Type
- Type
-
getTypeDisplayName( [cx])
-
Gets the friendly type display name for this object.
Parameters:
Name Type Argument Description cxObject <optional>
a context to be passed down to Type
- Since:
-
- Niagara 4.10
- Inherited From:
- See:
-
- baja.Type#getDisplayName
Returns:
If no context is provided, the type
display name is returned synchronously as a string. If context provided,
the type display name is resolved via a promise as a string.- Type
- Promise.<string> | string
-
make( [obj])
-
Make a
RelTime.Parameters:
Name Type Argument Description objObject | Number <optional>
the Object Literal or the number of milliseconds.
Properties
Name Type Argument Description daysNumber <optional>
the number of days.
hoursNumber <optional>
the number of hours.
minutesNumber <optional>
the number of minutes.
secondsNumber <optional>
the number of seconds.
msNumber <optional>
the number of milliseconds.
- Overrides:
Returns:
- Type
- baja.RelTime
Example
//This method can take a number of milliseconds of an Object Literal with //the method's argument... var rt1 = baja.$("baja:RelTime").make(1000); // One second // ...or we can specify an Object Literal for more arguments... // Create a RelTime with 2 days + 2 hours + 2 minutes + 2 seconds + 2 milliseconds... var rt2 = baja.$("baja:RelTime").make({ days: 2, hours: 2, minutes: 2, seconds: 2, ms: 2 }); -
newCopy( [exact])
-
Every value may be cloned using the
newCopymethod.Please note that
Simples are immutable so they don't
allocate a new instance.Parameters:
Name Type Argument Description exactBoolean <optional>
true if an exact copy of the value should be
made (only valid in the Component architecture).- Inherited From:
- See:
Returns:
a copy of the value (or the same instance if the value is a
Simple). -
toFriendlyString()
-
Returns a friendly string indicating the time interval from the present
moment. For example: "right now", "a few seconds ago", "3 months from now",
"an hour ago".- Since:
-
- Niagara 4.8
Returns:
a human-readable string indicating the time interval, relative to the present moment
- Type
- Promise.<string>
-
toString( [cx])
-
Return a
Stringrepresentation of aRelTime.Parameters:
Name Type Argument Description cxObject <optional>
the context.
Properties
Name Type Argument Default Description showMillisecondsBoolean <optional>
true set to false to hide milliseconds.
showSecondsBoolean <optional>
true set to false to hide seconds. If
showSeconds is false then milliseconds will not be shown.showMinutesBoolean <optional>
true set to false to hide minutes.
showHoursBoolean <optional>
true set to false to hide hours.
showDaysBoolean <optional>
true set to false to hide days.
- Overrides:
Returns:
if context is given, a Promise that
resolves to a localized string; otherwise an unlocalized string- Type
- String | Promise.<string>
Example
// IMPORTANT NOTE // // If a unit is greater than zero but the show flag for it is set to // false, then its value will get carried over to the leftmost shown // unit. var relTime = baja.RelTime.make({ hours: 1, seconds: 1 }); // 1hour 1sec relTime.toString(); // 60mins 1sec relTime.toString({ showHours: false }); // 3601secs relTime.toString({ showHours: false, showMinutes: false }); -
valueOf()
-
Return number of milliseconds.
- Overrides:
Returns:
- Type
- Number