From f27d6e947747402bd784705ceed9abff18e7da8c Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Tue, 18 Jun 2024 09:34:03 -0500 Subject: [PATCH] Migration to Sugarjs Date formats and parsing --- .../add-subtract-time/add-subtract-time.ts | 5 +- .../actions/compare-dates/compare-dates.ts | 2 +- .../convert-html-to-markdown.ts | 2 +- .../convert-html-to-text.ts | 2 +- .../convert-json-to-string.ts | 2 +- .../convert-markdown-to-html.ts | 2 +- .../date-time-format/date-time-format.ts | 10 +- .../extract-by-regular-expression.ts | 2 +- .../extract-email-address.ts | 2 +- .../actions/extract-number/extract-number.ts | 2 +- .../extract-phone-number.ts | 2 +- .../actions/extract-url/extract-url.ts | 2 +- .../format-currency/format-currency.ts | 2 +- .../actions/format-number/format-number.ts | 2 +- .../actions/parse-json/parse-json.ts | 2 +- .../actions/replace-text/replace-text.ts | 2 +- .../set-default-value/set-default-value.ts | 2 +- .../actions/split-text/split-text.ts | 26 +-- .../actions/transform-case/transform-case.ts | 2 +- .../trim-whitespace/trim-whitespace.ts | 2 +- .../actions/url-decode/url-decode.ts | 2 +- .../actions/url-encode/url-encode.ts | 2 +- .../common/date-time/commonDateTime.ts | 1 + .../common/date-time/dateFormats.ts | 196 +++++------------- components/formatting/package.json | 4 +- pnpm-lock.yaml | 16 +- 26 files changed, 112 insertions(+), 184 deletions(-) diff --git a/components/formatting/actions/add-subtract-time/add-subtract-time.ts b/components/formatting/actions/add-subtract-time/add-subtract-time.ts index dfc2131b3b2a4..325fa9af7fdfd 100644 --- a/components/formatting/actions/add-subtract-time/add-subtract-time.ts +++ b/components/formatting/actions/add-subtract-time/add-subtract-time.ts @@ -6,6 +6,7 @@ import { DATE_FORMAT_PARSE_MAP, DEFAULT_FORMAT_VALUE, } from "../../common/date-time/dateFormats"; import { DATE_TIME_UNITS } from "../../common/date-time/dateTimeUnits"; +import sugar from "sugar"; const OPERATION_OPTIONS = { ADD: "Add", @@ -17,7 +18,7 @@ export default defineAction({ name: "[Date/Time] Add/Subtract Time", description: "Add or subtract time from a given input", key: "formatting-add-subtract-time", - version: "0.0.4", + version: "0.0.5", type: "action", props: { ...commonDateTime.props, @@ -85,7 +86,7 @@ export default defineAction({ const format = outputFormat ?? this.inputFormat ?? DEFAULT_FORMAT_VALUE; try { const { outputFn } = DATE_FORMAT_PARSE_MAP.get(format); - const output = outputFn(new Date(result)); + const output = outputFn(sugar.Date.create(result)); $.export( "$summary", diff --git a/components/formatting/actions/compare-dates/compare-dates.ts b/components/formatting/actions/compare-dates/compare-dates.ts index 6915f8a5ecb01..c52735ac7f779 100644 --- a/components/formatting/actions/compare-dates/compare-dates.ts +++ b/components/formatting/actions/compare-dates/compare-dates.ts @@ -9,7 +9,7 @@ export default defineAction({ description: "Get the duration between two dates in days, hours, minutes, and seconds along with checking if they are the same.", key: "formatting-compare-dates", - version: "0.0.4", + version: "0.0.5", type: "action", props: { ...commonDateTime.props, diff --git a/components/formatting/actions/convert-html-to-markdown/convert-html-to-markdown.ts b/components/formatting/actions/convert-html-to-markdown/convert-html-to-markdown.ts index b7d69d3301340..7ac0ce4fe1650 100644 --- a/components/formatting/actions/convert-html-to-markdown/convert-html-to-markdown.ts +++ b/components/formatting/actions/convert-html-to-markdown/convert-html-to-markdown.ts @@ -7,7 +7,7 @@ export default defineAction({ name: "[Text] Convert HTML to Markdown", description: "Convert valid HTML to Markdown text", key: "formatting-convert-html-to-markdown", - version: "0.0.5", + version: "0.0.6", type: "action", props: { app, diff --git a/components/formatting/actions/convert-html-to-text/convert-html-to-text.ts b/components/formatting/actions/convert-html-to-text/convert-html-to-text.ts index c7208bc71fde2..2c7c9e96970d0 100644 --- a/components/formatting/actions/convert-html-to-text/convert-html-to-text.ts +++ b/components/formatting/actions/convert-html-to-text/convert-html-to-text.ts @@ -6,7 +6,7 @@ export default defineAction({ name: "[Text] Convert HTML to text", description: "Convert valid HTML to text", key: "formatting-convert-html-to-text", - version: "0.0.3", + version: "0.0.4", type: "action", props: { app, diff --git a/components/formatting/actions/convert-json-to-string/convert-json-to-string.ts b/components/formatting/actions/convert-json-to-string/convert-json-to-string.ts index 2e0214e2a06e8..3e8aeca735984 100644 --- a/components/formatting/actions/convert-json-to-string/convert-json-to-string.ts +++ b/components/formatting/actions/convert-json-to-string/convert-json-to-string.ts @@ -5,7 +5,7 @@ export default defineAction({ name: "[Data] Convert JSON to String", description: "Convert an object to a JSON format string", key: "formatting-convert-json-to-string", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/convert-markdown-to-html/convert-markdown-to-html.ts b/components/formatting/actions/convert-markdown-to-html/convert-markdown-to-html.ts index 11c4d4ccfef93..6b166034730c0 100644 --- a/components/formatting/actions/convert-markdown-to-html/convert-markdown-to-html.ts +++ b/components/formatting/actions/convert-markdown-to-html/convert-markdown-to-html.ts @@ -7,7 +7,7 @@ export default defineAction({ name: "[Text] Convert Markdown to HTML", description: "Convert Markdown text to HTML", key: "formatting-convert-markdown-to-html", - version: "0.0.5", + version: "0.0.6", type: "action", props: { app, diff --git a/components/formatting/actions/date-time-format/date-time-format.ts b/components/formatting/actions/date-time-format/date-time-format.ts index 1550fe76df71b..1b786bc5f0bbe 100644 --- a/components/formatting/actions/date-time-format/date-time-format.ts +++ b/components/formatting/actions/date-time-format/date-time-format.ts @@ -3,14 +3,14 @@ import { ConfigurationError } from "@pipedream/platform"; import { DATE_FORMAT_PARSE_MAP } from "../../common/date-time/dateFormats"; import commonDateTime from "../../common/date-time/commonDateTime"; import app from "../../app/formatting.app"; -import moment from "moment"; +import sugar from "sugar"; export default defineAction({ ...commonDateTime, name: "[Date/Time] Format", - description: "Format a date string to another date string", + description: "Format a date string to another date string. For more examples on formatting, see the [Sugar Date Format](https://sugarjs.com/dates/#/Formatting) documentation.", key: "formatting-date-time-format", - version: "0.0.5", + version: "0.0.6", type: "action", props: { ...commonDateTime.props, @@ -19,7 +19,7 @@ export default defineAction({ app, "outputFormat", ], - description: "The format to convert the date to.", + description: "The format to convert the date to. For more examples on formatting, see the [Sugar Date Format](https://sugarjs.com/dates/#/Formatting) documentation.", optional: false, }, }, @@ -32,7 +32,7 @@ export default defineAction({ const response = DATE_FORMAT_PARSE_MAP.get(outputFormat); const output = response ? response.outputFn(dateObj) - : moment(dateObj).format(outputFormat); + : sugar.Date.format(dateObj, outputFormat); $.export("$summary", "Successfully formatted date/time"); return output; diff --git a/components/formatting/actions/extract-by-regular-expression/extract-by-regular-expression.ts b/components/formatting/actions/extract-by-regular-expression/extract-by-regular-expression.ts index 34a23f54e4f37..a13d59389d186 100644 --- a/components/formatting/actions/extract-by-regular-expression/extract-by-regular-expression.ts +++ b/components/formatting/actions/extract-by-regular-expression/extract-by-regular-expression.ts @@ -7,7 +7,7 @@ export default defineAction({ description: "Find a match for a regular expression pattern. Returns all matched groups with start and end position.", key: "formatting-extract-by-regular-expression", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/extract-email-address/extract-email-address.ts b/components/formatting/actions/extract-email-address/extract-email-address.ts index 19eb3575e78be..969a20211d30a 100644 --- a/components/formatting/actions/extract-email-address/extract-email-address.ts +++ b/components/formatting/actions/extract-email-address/extract-email-address.ts @@ -7,7 +7,7 @@ export default defineAction({ description: "Find an email address out of a text field. Finds the first email address only.", key: "formatting-extract-email-address", - version: "0.0.5", + version: "0.0.6", type: "action", props: { ...commonExtractText.props, diff --git a/components/formatting/actions/extract-number/extract-number.ts b/components/formatting/actions/extract-number/extract-number.ts index 7aaa2f7556090..69443b4443ffd 100644 --- a/components/formatting/actions/extract-number/extract-number.ts +++ b/components/formatting/actions/extract-number/extract-number.ts @@ -7,7 +7,7 @@ export default defineAction({ description: "Find a number out of a text field. Finds the first number only.", key: "formatting-extract-number", - version: "0.0.4", + version: "0.0.5", type: "action", props: { ...commonExtractText.props, diff --git a/components/formatting/actions/extract-phone-number/extract-phone-number.ts b/components/formatting/actions/extract-phone-number/extract-phone-number.ts index c3e6b90383b25..592e3361d2c81 100644 --- a/components/formatting/actions/extract-phone-number/extract-phone-number.ts +++ b/components/formatting/actions/extract-phone-number/extract-phone-number.ts @@ -7,7 +7,7 @@ export default defineAction({ description: "Find a complete phone number out of a text field. Finds the first number only.", key: "formatting-extract-phone-number", - version: "0.0.4", + version: "0.0.5", type: "action", props: { ...commonExtractText.props, diff --git a/components/formatting/actions/extract-url/extract-url.ts b/components/formatting/actions/extract-url/extract-url.ts index 5bc9e4ece9218..311907d012875 100644 --- a/components/formatting/actions/extract-url/extract-url.ts +++ b/components/formatting/actions/extract-url/extract-url.ts @@ -7,7 +7,7 @@ export default defineAction({ description: "Find a web URL out of a text field. Finds the first URL only.", key: "formatting-extract-url", - version: "0.0.4", + version: "0.0.5", type: "action", props: { ...commonExtractText.props, diff --git a/components/formatting/actions/format-currency/format-currency.ts b/components/formatting/actions/format-currency/format-currency.ts index ef77d9c883e34..1a54078356603 100644 --- a/components/formatting/actions/format-currency/format-currency.ts +++ b/components/formatting/actions/format-currency/format-currency.ts @@ -9,7 +9,7 @@ export default defineAction({ name: "[Numbers] Format Currency", description: "Format a number as a currency", key: "formatting-format-currency", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/format-number/format-number.ts b/components/formatting/actions/format-number/format-number.ts index d297008408cdd..b8292130f87d6 100644 --- a/components/formatting/actions/format-number/format-number.ts +++ b/components/formatting/actions/format-number/format-number.ts @@ -11,7 +11,7 @@ export default defineAction({ description: "Format a number to a new style. Does not perform any rounding or padding of the number.", key: "formatting-format-number", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/parse-json/parse-json.ts b/components/formatting/actions/parse-json/parse-json.ts index e70b0492dca73..ad9b72b7085c6 100644 --- a/components/formatting/actions/parse-json/parse-json.ts +++ b/components/formatting/actions/parse-json/parse-json.ts @@ -5,7 +5,7 @@ export default defineAction({ name: "[Data] Parse JSON", description: "Parse a JSON string", key: "formatting-parse-json", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/replace-text/replace-text.ts b/components/formatting/actions/replace-text/replace-text.ts index d2440017994da..18e8160f3309b 100644 --- a/components/formatting/actions/replace-text/replace-text.ts +++ b/components/formatting/actions/replace-text/replace-text.ts @@ -9,7 +9,7 @@ export default defineAction({ description: "Replace all instances of any character, word or phrase in the text with another character, word or phrase.", key: "formatting-replace-text", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/set-default-value/set-default-value.ts b/components/formatting/actions/set-default-value/set-default-value.ts index 02b4c8282b026..15ef43aea4e6c 100644 --- a/components/formatting/actions/set-default-value/set-default-value.ts +++ b/components/formatting/actions/set-default-value/set-default-value.ts @@ -5,7 +5,7 @@ export default defineAction({ name: "[Text] Set Default Value", description: "Return a default value if the text is empty", key: "formatting-set-default-value", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/split-text/split-text.ts b/components/formatting/actions/split-text/split-text.ts index 88bed71daa300..19bd83790c698 100644 --- a/components/formatting/actions/split-text/split-text.ts +++ b/components/formatting/actions/split-text/split-text.ts @@ -10,7 +10,7 @@ export default defineAction({ description: "Split the text on a character or word and return one or all segments", key: "formatting-split-text", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, @@ -52,22 +52,22 @@ export default defineAction({ summary = `Successfully split text into ${length} segments`; switch (segmentIndex) { - case INDEX_ALL_SEGMENTS: - result = arrResults; - break; + case INDEX_ALL_SEGMENTS: + result = arrResults; + break; // this case would not be needed if 0 was accepted as an option // see issue #5429 - case INDEX_ALL_SEGMENTS * -1: - result = arrResults[0]; - break; + case INDEX_ALL_SEGMENTS * -1: + result = arrResults[0]; + break; - default: - result = - arrResults[segmentIndex < 0 - ? length + segmentIndex - : segmentIndex]; - break; + default: + result = + arrResults[segmentIndex < 0 + ? length + segmentIndex + : segmentIndex]; + break; } } diff --git a/components/formatting/actions/transform-case/transform-case.ts b/components/formatting/actions/transform-case/transform-case.ts index 2b81fd94bf2a2..974b4c60b8a96 100644 --- a/components/formatting/actions/transform-case/transform-case.ts +++ b/components/formatting/actions/transform-case/transform-case.ts @@ -9,7 +9,7 @@ export default defineAction({ name: "[Text] Transform Case", description: "Transform case for a text input", key: "formatting-transform-case", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/trim-whitespace/trim-whitespace.ts b/components/formatting/actions/trim-whitespace/trim-whitespace.ts index 282bdb3372515..2fd83ebdb787f 100644 --- a/components/formatting/actions/trim-whitespace/trim-whitespace.ts +++ b/components/formatting/actions/trim-whitespace/trim-whitespace.ts @@ -5,7 +5,7 @@ export default defineAction({ name: "[Text] Trim Whitespace", description: "Removes leading and trailing whitespace", key: "formatting-trim-whitespace", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/url-decode/url-decode.ts b/components/formatting/actions/url-decode/url-decode.ts index f2b2a2afda929..c885a830257a4 100644 --- a/components/formatting/actions/url-decode/url-decode.ts +++ b/components/formatting/actions/url-decode/url-decode.ts @@ -5,7 +5,7 @@ export default defineAction({ name: "[Text] Decode URL", description: "Decode a URL string", key: "formatting-url-decode", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/actions/url-encode/url-encode.ts b/components/formatting/actions/url-encode/url-encode.ts index aacc089c8c67e..62a10b2d512ae 100644 --- a/components/formatting/actions/url-encode/url-encode.ts +++ b/components/formatting/actions/url-encode/url-encode.ts @@ -5,7 +5,7 @@ export default defineAction({ name: "[Text] Encode URL", description: "Encode a string as a URL", key: "formatting-url-encode", - version: "0.0.4", + version: "0.0.5", type: "action", props: { app, diff --git a/components/formatting/common/date-time/commonDateTime.ts b/components/formatting/common/date-time/commonDateTime.ts index 9aa26cd1a51b6..7180f1f97c694 100644 --- a/components/formatting/common/date-time/commonDateTime.ts +++ b/components/formatting/common/date-time/commonDateTime.ts @@ -9,6 +9,7 @@ export default { props: { app, inputDate: { + description: "A valid date string, in the format selected in **Input Format**. If the format is not set, Pipedream will attempt to infer it using the parser from [Sugar Date library](https://sugarjs.com/dates/#/Parsing).", propDefinition: [ app, "inputDate", diff --git a/components/formatting/common/date-time/dateFormats.ts b/components/formatting/common/date-time/dateFormats.ts index 2a5cd14493e99..e70d672f909d8 100644 --- a/components/formatting/common/date-time/dateFormats.ts +++ b/components/formatting/common/date-time/dateFormats.ts @@ -1,5 +1,6 @@ +import sugar from "sugar"; + interface DateFormat { - label: string; value: string; inputFn?: (s: string) => Date; outputFn: (d: Date) => string | number; @@ -9,236 +10,154 @@ export const DEFAULT_FORMAT_VALUE = "YYYY-MM-DDTHH:mm:ssZ"; export const DEFAULT_INPUT_FUNCTION: DateFormat["inputFn"] = (str) => { const num = Number(str); - return new Date(num * 1000 || str); + return sugar.Date.create(num * 1000 || str); }; // https://tc39.es/ecma402/#table-datetimeformat-components const DATE_FORMATS: DateFormat[] = [ { - label: "Sun Jan 22 23:04:05 -0000 2006", - value: "ddd MMM DD HH:mm:ss Z YYYY", + value: "Sun Jan 22 23:04:05 +0000 2006", outputFn(dateObj) { - const date = dateObj - .toLocaleDateString("en-US", { - weekday: "short", - day: "2-digit", - month: "short", - }) - .replace(/,/g, ""); - - const time = dateObj.toLocaleTimeString("en-GB"); - - return `${date} ${time} -0000 ${dateObj.getFullYear()}`; + return sugar.Date.format(dateObj, "%a %b %d %H:%M:%S {ZZ} %Y"); }, }, { - label: "January 22 2006 23:04:05", - value: "MMMM DD YYYY HH:mm:ss", + value: "January 22 2006 23:04:05", outputFn(dateObj) { - const date = dateObj - .toLocaleString("en-US", { - day: "2-digit", - month: "long", - year: "numeric", - }) - .replace(/,/g, ""); - - const time = dateObj.toLocaleTimeString("en-GB"); - - return `${date} ${time}`; + return sugar.Date.format(dateObj, "%B %d %Y %H:%M:%S"); }, }, { - label: "January 22 2006", - value: "MMMM DD YYYY", + value: "January 22 2006", outputFn(dateObj) { - return dateObj - .toLocaleString("en-US", { - day: "2-digit", - month: "long", - year: "numeric", - }) - .replace(/,/g, ""); + return sugar.Date.format(dateObj, "%B %d %Y"); }, }, { - label: "Jan 22 2006", - value: "MMM DD YYYY", + value: "Jan 22 2006", outputFn(dateObj) { - return dateObj - .toLocaleString("en-US", { - day: "2-digit", - month: "short", - year: "numeric", - }) - .replace(/,/g, ""); + return sugar.Date.format(dateObj, "%b %d %Y"); }, }, { - label: "2006-01-22T23:04:05", - value: "YYYY-MM-DDTHH:mm:ss", + value: "2006-01-22T23:04:05", outputFn(dateObj) { - return dateObj - .toISOString() - .replace(/\.[0-9]{3}/g, "") - .replace(/Z/, "-0000"); + return [ + sugar.Date.format(dateObj, "%Y-%m-%d"), + "T", + sugar.Date.format(dateObj, "%H:%M:%S"), + ].join(""); }, }, { - label: "2006-01-22T23:04:05-0000", - value: "YYYY-MM-DDTHH:mm:ss", + value: "2006-01-22T23:04:05+0000", outputFn(dateObj) { - return dateObj - .toISOString() - .replace(/\.[0-9]{3}/g, "") - .replace(/Z/, "-0000"); + return [ + sugar.Date.format(dateObj, "%Y-%m-%d"), + "T", + sugar.Date.format(dateObj, "%H:%M:%S{ZZ}"), + ].join(""); }, }, { - label: "2006-01-22 23:04:05 -0000", - value: "YYYY-MM-DD HH:mm:ss Z", + value: "2006-01-22 23:04:05 +0000", outputFn(dateObj) { - return dateObj - .toISOString() - .replace(/T|(\.[0-9]{3})/g, " ") - .replace(/Z/, "-0000"); + return sugar.Date.format(dateObj, "%Y-%m-%d %H:%M:%S {ZZ}"); }, }, { - label: "2006-01-22 23:04", - value: "YYYY-MM-DD HH:mm", + value: "2006-01-22 23:04", outputFn(dateObj) { - return dateObj - .toISOString() - .replace(/T/g, " ") - .replace(/:[0-9]{2}\.[0-9]{3}Z/, ""); + return sugar.Date.format(dateObj, "%Y-%m-%d %H:%M"); }, }, { - label: "2006-01-22", - value: "YYYY-MM-DD", + value: "2006-01-22", outputFn(dateObj) { - return dateObj - .toLocaleDateString("en-GB", { - day: "2-digit", - month: "2-digit", - year: "numeric", - }) - .split("/") - .reverse() - .join("-"); + return sugar.Date.format(dateObj, "%Y-%m-%d"); }, }, { - label: "01-22-2006", - value: "MM-DD-YYYY", + value: "01-22-2006", outputFn(dateObj) { - return dateObj - .toLocaleDateString("en-US", { - day: "2-digit", - month: "2-digit", - year: "numeric", - }) - .replace(/\//g, "-"); + return sugar.Date.format(dateObj, "%m-%d-%Y"); }, }, { - label: "01/22/2006", - value: "MM/DD/YYYY", + value: "01/22/2006", outputFn(dateObj) { - return dateObj.toLocaleDateString("en-US", { - day: "2-digit", - month: "2-digit", - year: "numeric", - }); + return sugar.Date.format(dateObj, "%m/%d/%Y"); }, }, { - label: "01/22/06", - value: "MM/DD/YY", + value: "01/22/06", outputFn(dateObj) { - return dateObj.toLocaleDateString("en-US", { - day: "2-digit", - month: "2-digit", - year: "2-digit", - }); + return sugar.Date.format(dateObj, "%m/%d/{yy}"); }, }, { - label: "22-01-2006", - value: "DD-MM-YYYY", + value: "22-01-2006", inputFn(str) { const [ day, month, year, ] = str.split("-"); - const date = new Date( - Date.UTC(Number(year), Number(month) - 1, Number(day)), - ); - return date; + return sugar.Date.create(`${year}-${month}-${day}`, { + fromUTC: true, + }); }, outputFn(dateObj) { - return dateObj.toLocaleDateString("en-GB").replace(/\//g, "-"); + return sugar.Date.format(dateObj, "%d-%m-%Y"); }, }, { - label: "22/01/2006", - value: "DD/MM/YYYY", + value: "22/01/2006", inputFn(str) { const [ day, month, year, ] = str.split("/"); - const date = new Date( - Date.UTC(Number(year), Number(month) - 1, Number(day)), - ); - return date; + return sugar.Date.create(`${year}-${month}-${day}`, { + fromUTC: true, + }); }, outputFn(dateObj) { - return dateObj.toLocaleDateString("en-GB"); + return sugar.Date.format(dateObj, "%d/%m/%Y"); }, }, { - label: "22/01/06", - value: "DD/MM/YY", + value: "22/01/06", inputFn(str) { const [ day, month, year, ] = str.split("/"); - const date = new Date( - Date.UTC(Number(year), Number(month) - 1, Number(day) + 2000), - ); - return date; + return sugar.Date.create(`${Number(year) + 2000}-${month}-${day}`, { + fromUTC: true, + }); }, outputFn(dateObj) { - return dateObj.toLocaleDateString("en-GB", { - day: "2-digit", - month: "2-digit", - year: "2-digit", - }); + return sugar.Date.format(dateObj, "%d/%m/{yy}"); }, }, { - label: "1137971045", - value: "Unix time (seconds)", + value: "Unix time (seconds) Eg. 1137971045", inputFn(str) { - return new Date(Number(str) * 1000); + return sugar.Date.create(Number(str) * 1000); }, outputFn(dateObj) { return dateObj.valueOf() / 1000; }, }, { - label: "1137971045000", - value: "Unix time (milliseconds)", + value: "Unix time (milliseconds) Eg. 1137971045000", inputFn(str) { - return new Date(Number(str)); + return sugar.Date.create(Number(str)); }, outputFn(dateObj) { return dateObj.valueOf(); @@ -263,9 +182,4 @@ const mapData: [ export const DATE_FORMAT_PARSE_MAP = new Map(mapData); -export const DATE_FORMAT_OPTIONS = DATE_FORMATS.map(({ - label, value, -}) => ({ - label, - value, -})); +export const DATE_FORMAT_OPTIONS = DATE_FORMATS.map(({ value }) => value); diff --git a/components/formatting/package.json b/components/formatting/package.json index d12f50ec9b927..434033f0350e5 100644 --- a/components/formatting/package.json +++ b/components/formatting/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/formatting", - "version": "0.1.3", + "version": "0.2.0", "description": "Pipedream Formatting Components", "main": "dist/app/formatting.app.mjs", "keywords": [ @@ -20,9 +20,9 @@ "@pipedream/types": "^0.1.4", "html-to-text": "^8.2.1", "linkedom": "^0.14.26", - "moment": "^2.29.4", "pluralize": "^8.0.0", "showdown": "^2.1.0", + "sugar": "^2.0.6", "title-case": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4943132b40c1e..6c3fc1a490f8f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3093,18 +3093,18 @@ importers: '@pipedream/types': ^0.1.4 html-to-text: ^8.2.1 linkedom: ^0.14.26 - moment: ^2.29.4 pluralize: ^8.0.0 showdown: ^2.1.0 + sugar: ^2.0.6 title-case: ^3.0.3 dependencies: '@pipedream/platform': 1.5.1 '@pipedream/types': 0.1.6 html-to-text: 8.2.1 linkedom: 0.14.26 - moment: 2.29.4 pluralize: 8.0.0 showdown: 2.1.0 + sugar: 2.0.6 title-case: 3.0.3 components/formbricks: @@ -30658,6 +30658,18 @@ packages: - typescript dev: true + /sugar-core/2.0.6: + resolution: {integrity: sha512-YmLFysR3Si6RImqL1+aB6JH81EXxvXn5iXhPf2PsjfoUYEwCxFDYCQY+zC3WqviuGWzxFaSkkJvkUE05Y03L5Q==} + engines: {node: '>= 0.8.23'} + dev: false + + /sugar/2.0.6: + resolution: {integrity: sha512-s0P2/pjJtAD9VA44+2Gqm3NdC4v+08melA6YubOxzshu628krTbn95/M2GWMrI9rYspZMpYBIrChR46fjQ7xsQ==} + engines: {node: '>= 0.8.23'} + dependencies: + sugar-core: 2.0.6 + dev: false + /superagent-proxy/3.0.0_superagent@7.1.5: resolution: {integrity: sha512-wAlRInOeDFyd9pyonrkJspdRAxdLrcsZ6aSnS+8+nu4x1aXbz6FWSTT9M6Ibze+eG60szlL7JA8wEIV7bPWuyQ==} engines: {node: '>=6'}