Skip to content

Commit

Permalink
🐛 Fix due_datetime formatting on Todoist (#2491)
Browse files Browse the repository at this point in the history
* Fixed due_datetime formatting

Signed-off-by: Ivan Lebedev <lisgml@gmail.com>

* Option to specify due_string language

Signed-off-by: Ivan Lebedev <lisgml@gmail.com>

* Removed debug imports

Signed-off-by: Ivan Lebedev <lisgml@gmail.com>
  • Loading branch information
X-pech authored Dec 19, 2021
1 parent d6c7528 commit 6a2d970
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/nodes-base/nodes/Todoist/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import {
IDataObject, NodeApiError,
} from 'n8n-workflow';

export function FormatDueDatetime(ISOString: string): string {
// Assuming that the problem with incorrect date format was caused by milliseconds
// Replacing the last 5 characters of ISO-formatted string with just Z char
return ISOString.replace(new RegExp('.000Z$'), 'Z');
}

export async function todoistApiRequest(
this:
| IHookFunctions
Expand Down
29 changes: 26 additions & 3 deletions packages/nodes-base/nodes/Todoist/Todoist.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {

import {
todoistApiRequest,
FormatDueDatetime,
} from './GenericFunctions';

interface IBodyCreateTask {
Expand Down Expand Up @@ -276,6 +277,13 @@ export class Todoist implements INodeType {
default: '',
description: 'Human defined task due date (ex.: “next Monday”, “Tomorrow”). Value is set using local (not UTC) time.',
},
{
displayName: 'Due String Locale',
name: 'dueLang',
type: 'string',
default: '',
description: '2-letter code specifying language in case due_string is not written in English.',
},
{
displayName: 'Priority',
name: 'priority',
Expand Down Expand Up @@ -357,7 +365,7 @@ export class Todoist implements INodeType {
],
operation: [
'getAll',
],
],
},
},
options: [
Expand Down Expand Up @@ -449,6 +457,13 @@ export class Todoist implements INodeType {
default: '',
description: 'Human defined task due date (ex.: “next Monday”, “Tomorrow”). Value is set using local (not UTC) time.',
},
{
displayName: 'Due String Locale',
name: 'dueLang',
type: 'string',
default: '',
description: '2-letter code specifying language in case due_string is not written in English.',
},
{
displayName: 'Labels',
name: 'labels',
Expand Down Expand Up @@ -573,13 +588,17 @@ export class Todoist implements INodeType {
}

if (options.dueDateTime) {
body.due_datetime = options.dueDateTime as string;
body.due_datetime = FormatDueDatetime(options.dueDateTime as string);
}

if (options.dueString) {
body.due_string = options.dueString as string;
}

if (options.dueLang) {
body.due_lang = options.dueLang as string;
}

if (labels !== undefined && labels.length !== 0) {
body.label_ids = labels;
}
Expand Down Expand Up @@ -670,13 +689,17 @@ export class Todoist implements INodeType {
}

if (updateFields.dueDateTime) {
body.due_datetime = updateFields.dueDateTime as string;
body.due_datetime = FormatDueDatetime(updateFields.dueDateTime as string);
}

if (updateFields.dueString) {
body.due_string = updateFields.dueString as string;
}

if (updateFields.dueLang) {
body.due_lang = updateFields.dueLang as string;
}

if (updateFields.labels !== undefined &&
Array.isArray(updateFields.labels) &&
updateFields.labels.length !== 0) {
Expand Down

0 comments on commit 6a2d970

Please sign in to comment.