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
-
RelTime
instance for a day.Type:
-
<static> DEFAULT :baja.RelTime
-
Default
RelTime
instance.Type:
-
<static> HOUR :baja.RelTime
-
RelTime
instance 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
-
RelTime
instance for a minute.Type:
-
<static> SECOND :baja.RelTime
-
RelTime
instance for a second.Type:
Methods
-
<static> make( [obj])
-
Make a
RelTime
.Parameters:
Name Type Argument Description obj
Object | Number <optional>
the Object Literal or the number of milliseconds.
Properties
Name Type Argument Description days
Number <optional>
the number of days.
hours
Number <optional>
the number of hours.
minutes
Number <optional>
the number of minutes.
seconds
Number <optional>
the number of seconds.
ms
Number <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
decodeFromString
directly.Parameters:
Name Type Argument Description str
string batch
baja.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
RelTime
from aString
.Parameters:
Name Type Description str
String - Overrides:
Returns:
- Type
- baja.RelTime
-
encodeToString()
-
Encode the
RelTime
to 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 is
Array.<String> <optional>
An optional array of filters to add to the
agent query.batch
baja.comm.Batch 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
-
make( [obj])
-
Make a
RelTime
.Parameters:
Name Type Argument Description obj
Object | Number <optional>
the Object Literal or the number of milliseconds.
Properties
Name Type Argument Description days
Number <optional>
the number of days.
hours
Number <optional>
the number of hours.
minutes
Number <optional>
the number of minutes.
seconds
Number <optional>
the number of seconds.
ms
Number <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
newCopy
method.Please note that
Simple
s are immutable so they don't
allocate a new instance.Parameters:
Name Type Argument Description exact
Boolean <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
). -
toString( [cx])
-
Return a
String
representation of aRelTime
.Parameters:
Name Type Argument Description cx
Object <optional>
the context.
Properties
Name Type Argument Default Description showMillis
Boolean <optional>
true set to false to hide milliseconds.
showSeconds
Boolean <optional>
true set to false to hide seconds. If
showSeconds is false then milliseconds will not be shown.showMinutes
Boolean <optional>
true set to false to hide minutes.
showHours
Boolean <optional>
true set to false to hide hours.
showDays
Boolean <optional>
true set to false to hide days.
- Overrides:
Returns:
- Type
- 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