utils
Source: /
Utility Functions
Methods
date(format[, daysOffset]) → String
Return a date in the given format with the given number days offset from the current date.
Example
// Set a date two days in the future
var format = "MM/dd/yyyy";
b.type("#departureDate", utils.date(format, 2));
Parameters
Name | Type | Optional | Description |
---|---|---|---|
format |
String |
|
The time format |
daysOffset |
Number |
Yes |
The day offset |
- Returns
-
String
The formatted date as a string
dateTime(format[, Date]) → String
Format the current (or given) date time.
Example
var format = "MM-dd-YY-hh-mm-ss-ms";
b.type("#decsription", "description-" + utils.dateTime(format));
Parameters
Name | Type | Optional | Description |
---|---|---|---|
format |
String |
|
The date time format |
Date |
Date |
Yes |
time to format, if not specified current date will be used |
- Returns
-
String
Date time as string
random(max) → Number
Return a random integer in the range 0 - (max - 1)
Example
// get a random element from an array
var airports = ['san', 'sfo', 'pdx', 'smf', 'lax'];
var origin = airports[utils.random(airports.length)];
Parameter
Name | Type | Optional | Description |
---|---|---|---|
max |
Number |
|
The (max - 1) of the returned random number |
- Returns
-
Number
Random integer between 0 - (max - 1)
randomElement(array) → Object
Return a random element from the given array
Example
// get a random element from an array
var airports = ['san', 'sfo', 'pdx', 'smf', 'lax'];
var origin = utils.randomElement(airports);
Parameter
Name | Type | Optional | Description |
---|---|---|---|
array |
Array |
|
The array to select a random element from |
- Returns
-
Object
Random element from the given array, or null if the array is empty