Scripting utils
Scripting utils is a complementary library of JavaScript functions that is part of the Cloud Studio platform and whose methods can be invoked from user-built JavaScript scripts in actions.
Properties
| utcNow (DateTime) |
|---|
| The utcNow property represents the current date and time in UTC |
| Examples |
| let now = utils.utcNow; |
Date and time functions
| DateTime addDays (double days, DateTime dateTime) |
|---|
| The addDays function allows adding and also subtracting days from a date |
| ExamplesThis example adds and subtracts two days from the current UTC date and time |
| //Add two days let date = utils.addDays(2, utils.utcNow); // Subtract two days let date = utils.addDays(-2, utils.utcNow); |
| DateTime addHours(double hours, DateTime dateTime) |
|---|
| The addHours function allows adding and also subtracting hours from a date |
| ExamplesThis example shows how to add one hour to the current date and time and how to subtract one hour from the current UTC time |
| //Add one hour let date = utils.addHours(1, utils.utcNow); //Subtract one hour let date = utils.addHours(-1, utils.utcNow); |
| DateTime addMinutes(double minutes, DateTime dateTime) |
|---|
| The addMinutes function allows adding and also subtracting minutes from a date |
| ExamplesThis example adds one minute to the current UTC date and time and subtracts one minute from the current UTC time |
| //Add one minute let date = utils.addMinutes(1, datetime); // Subtract one minute let date = utils.addMinutes(-1, datetime); |
| DateTime addMonths(double months, DateTime dateTime) |
|---|
| The addMonths function allows adding and also subtracting months from a date |
| ExamplesThis example adds and subtracts six months from the current date and time |
| //Add six months let date = utils.addMonths(6, datetime); //Subtract six months let date = utils.addMonths(-6, datetime); |
| DateTime addSeconds(double seconds, DateTime dateTime) |
|---|
| The addSeconds function allows adding and subtracting seconds from a date |
| ExamplesThis example adds and subtracts 25 seconds from the current date and time |
| // Add seconds let date = utils.addSeconds(25, datetime); // Subtract seconds let date = utils.addSeconds(-25, datetime); |
| DateTime addYears(double years, DateTime dateTime) |
|---|
| The addYears function allows adding and subtracting years from a date |
| ExamplesThis example adds and subtracts 3 years from the current date and time |
| // Add years let date = utils.addYears(3, datetime); // Subtract years let date = utils.addYears(3, datetime); |
| DateTime getLastMonday(*DateTime) |
|---|
| The getLastMonday() function gets the Monday before the current UTC date and time |
| ExamplesThis example gets the Monday before the current UTC date and time or the Monday before the optional date and time parameter |
| let date = utils.getLastMonday(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mondate = utils.getLastMonday(myDate); env.log(date); |
| DateTime getNextMonday(*DateTime) |
|---|
| The getNextMonday() function gets the Monday after the current UTC date and time |
| ExamplesThis example gets the Monday after the current UTC date and time or the Monday after the optional date and time parameter |
| let date = utils.getNextMonday(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mondate = utils.getNextMonday(myDate); env.log(mondate); |
| DateTime getLastSunday(*DateTime) |
|---|
| The getLastSunday() function gets the last Sunday before the current UTC date and time |
| ExamplesThis example gets the last Sunday before the current UTC date and time or the last Sunday before the optional date and time parameter |
| let date = utils.getLastSunday(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getLastSunday(myDate); env.log(mydate); |
| DateTime getNextSunday(*DateTime) |
|---|
| The getNextSunday() function gets the Sunday after the current UTC date and time |
| ExamplesThis example gets the Sunday after the current UTC date and time or the Sunday after the optional date and time parameter |
| let date = utils.getNextSunday(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getNextSunday(myDate); env.log(mydate); |
| DateTime getFirstDayOfMonth(*DateTime) |
|---|
| The getFirstDayOfMonth() function gets the first day of the month of the current UTC date and time |
| ExamplesThis example gets the first day of the month of the current UTC date and time or the first day of the month of the optional date and time parameter |
| let date = utils.getFirstDayOfMonth(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getFirstDayOfMonth(myDate); env.log(mydate); |
| DateTime getLastDayOfMonth(*DateTime) |
|---|
| The getLastDayOfMonth() function gets the last day of the month of the current UTC date and time |
| ExamplesThis example gets the last day of the month of the current UTC date and time or the last day of the month of the optional date and time parameter |
| let date = utils.getLastDayOfMonth(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getLastDayOfMonth(myDate); env.log(mydate); |
| DateTime getFirstDayOfYear(*DateTime) |
|---|
| The getFirstDayOfYear() function gets the first day of the year of the current UTC date and time |
| ExamplesThis example gets the first day of the year of the current UTC date and time or the first day of the year of the optional date and time parameter |
| let date = utils.getFirstDayOfYear(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getFirstDayOfYear(myDate); env.log(mydate); |
| DateTime getLastDayOfYear(*DateTime) |
|---|
| The getLastDayOfYear() function gets the last day of the year of the current UTC date and time |
| ExamplesThis example gets the last day of the year of the current UTC date and time or the last day of the year of the optional date and time parameter |
| let date = utils.getLastDayOfYear(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getLastDayOfYear(myDate); env.log(mydate); |
| DateTime getFirstDayOfQuarter(*DateTime) |
|---|
| The getFirstDayOfQuarter() function gets the first day of the quarter of the current UTC date and time |
| ExamplesThis example gets the first day of the quarter of the current UTC date and time or the first day of the quarter of the optional date and time parameter |
| let date = utils.getFirstDayOfQuarter(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getFirstDayOfQuarter(myDate); env.log(mydate); |
| DateTime getLastDayOfQuarter(*DateTime) |
|---|
| The getLastDayOfQuarter() function gets the last day of the quarter of the current UTC date and time |
| ExamplesThis example gets the last day of the quarter of the current UTC date and time or the last day of the quarter of the optional date and time parameter |
| let date = utils.getLastDayOfQuarter(); env.log(date); let myDate = new Date('2024-06-16T03:24:00'); let mydate= utils.getLastDayOfQuarter(myDate); env.log(mydate); |
Interpolation functions
| double linearInterpolation(params double[] values) |
|---|
| The first parameter is the value to interpolate, the remaining parameters are points (x, y), with a minimum of 2 points (5 parameters total) and a maximum of 20 points (41 parameters total) |
| ExamplesThis example interpolates the value 1.5 to the values 1.1, 2.3, and 3 |
| const parameters = []; parameters.push(1.5, 1.1, 2.3 , 3) let interpolated = utils.linearInterpolation(parameters); |