Skip to content

Commit

Permalink
Migration to Sugarjs Date formats and parsing (#12480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcortes committed Jun 24, 2024
1 parent 6071489 commit 49e4877
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -96,6 +97,7 @@ export default defineAction({
);
return output;
} catch (err) {
console.log("Error parsing date", err);
throw new ConfigurationError("**Parse error** - check your input and if the selected format is correct.");
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
},
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/formatting/actions/extract-url/extract-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/formatting/actions/parse-json/parse-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/formatting/actions/replace-text/replace-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions components/formatting/actions/split-text/split-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/formatting/actions/url-decode/url-decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/formatting/actions/url-encode/url-encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions components/formatting/common/date-time/commonDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 49e4877

Please sign in to comment.