This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FlowUtils { | |
@InvocableMethod(label='Format Date/Time') | |
public static String[] format(FormatInput[] inputs) { | |
String[] outputs = new String[0]; | |
for (FormatInput input : inputs) { | |
outputs.add(input.dt.format(input.format, input.tz)); | |
} | |
return outputs; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Makes it easier to sort an array of values by allowing you to specify 1 or | |
* more key values for each array value. | |
*/ | |
public class KeySorter { | |
/** | |
* Represents a key that will be used to sort a value passed into `KeySorter`. | |
* This class is only addressable internally. | |
*/ | |
private class ComparableKey implements Comparable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Chris West | |
* Description: | |
* Makes it possible to easily loop through all of the instances of a pattern | |
* within a string and replace the matches with something different. | |
*/ | |
public class PatternReplacer { | |
public Matcher matcher {get; private set;} | |
public String match { | |
get { return p_match; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSONValue { | |
private Object objValue; | |
public JSONValue(String serialized) { | |
this.objValue = JSON.deserializeUntyped(serialized); | |
} | |
private JSONValue(Object unserialized) { | |
this.objValue = unserialized; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Takes a date and returns it as a string in the format | |
* `YYYY-MM-DDTHH:mm:ss.SSSZ`. If the `timeZone` given is `"UTC"` or `"GMT"` | |
* the `Z` will remain as `"Z"`, otherwise it will be replaced with the timezone | |
* offset (eg. `"-05:00"`). | |
* @param {Date} inputDate | |
* The date to convert to a JSON format. | |
* @param {?string=} timeZone | |
* Optional, defaults to the user's time zone. The time zone to use when | |
* getting the YMD format (eg. `"America/Los_Angeles"`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var formatIntlDate = (() => { | |
const CODE_TO_PROP_NAME = { | |
Y: ['year', 'numeric'], | |
M: ['month', 'long'], | |
D: ['day', 'numeric'], | |
WD: ['weekday', 'long'], | |
h: ['hour', '2-digit'], | |
m: ['minute', '2-digit'], | |
s: ['second', '2-digit'], | |
ms: ['fractionalSecondDigits', 3], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Reads the row values of the specified Google Sheet that was published to the | |
* web without needing an API key. | |
* @param {string} publishedURL | |
* The URL of the sheet that you want to read from as copied from the "Publish | |
* to the Web" modal in Google Sheets. To get the contents of a sheet other | |
* than the first one you must use the URL of that sheet when selecting it in | |
* the "Publish to the Web" modal in Google Sheets. | |
* @returns {Promise<(boolean|null|number|string)[][]>} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates comparer functions that can be passed to an array's `sort` function | |
* to sort the values by the criteria specified. | |
* @param {...GetComparerPath} paths | |
* Each path indicates the path to traverse starting at `a` and `b` to find | |
* which underlying values should be compared to each other. | |
* @returns {(a: any, b: any) => (-1|0|1)} | |
* The comparer function with the path data baked in. The return function | |
* when called will return `-1` if `a` is less than `b`, it will return `1` if | |
* `a` is greater than `b` and in all other cases it will return `0`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sorts an array of values using the criteria specified in a function. This is | |
* similar to the Python sort function in that `criteria` is run once for each | |
* value and then the return is used to sort the original values. Quick sort is | |
* used to sort the values. | |
* @template T | |
* @param {T[]} values | |
* The array of values that will be directly sorted and returned. | |
* @param {(value:T,index:number,values:T[])=>any} criteria | |
* A function that will return a value for each value in `values` indicating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A quick implementation of quick sort. | |
* @template T | |
* @param {T[]} values | |
* The values to sort. | |
* @returns {T[]} | |
* The sorted array of values. | |
*/ | |
function quickSort(values) { | |
const segments = [{start: 0, end: values.length - 1}]; |