Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed due_datetime formatting #2491

Merged
merged 3 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/nodes-base/nodes/Todoist/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ import {
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
returnJsonArray,
X-pech marked this conversation as resolved.
Show resolved Hide resolved
} from 'n8n-core';

import {
IDataObject, NodeApiError,
} from 'n8n-workflow';
import { Console } from 'console';
X-pech marked this conversation as resolved.
Show resolved Hide resolved

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:
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