mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(GoogleCalendar Node): Fix timezone
* Fix timezone in google calendar * change timezone additionalFields variable name in Google.Calendar.nodes.ts from timeZone to timezone * add timezone information to formated code Signed-off-by: 5pecia1 <pdpxpd@gmail.com> * ⚡ nodelinter fixes * 🔨 fixes for incorrect timezonez Co-authored-by: michael-radency <michael.k@radency.com>
This commit is contained in:
parent
e8500e6937
commit
3c5df3f892
|
@ -9,6 +9,7 @@ import {
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
JsonObject,
|
||||||
NodeApiError,
|
NodeApiError,
|
||||||
NodeOperationError,
|
NodeOperationError,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
@ -35,6 +36,7 @@ import {
|
||||||
import * as moment from 'moment-timezone';
|
import * as moment from 'moment-timezone';
|
||||||
|
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
import { moveMessagePortToContext } from 'worker_threads';
|
||||||
|
|
||||||
export class GoogleCalendar implements INodeType {
|
export class GoogleCalendar implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -61,6 +63,7 @@ export class GoogleCalendar implements INodeType {
|
||||||
displayName: 'Resource',
|
displayName: 'Resource',
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
|
noDataExpression: true,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Calendar',
|
name: 'Calendar',
|
||||||
|
@ -72,7 +75,7 @@ export class GoogleCalendar implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'event',
|
default: 'event',
|
||||||
description: 'The resource to operate on.',
|
description: 'The resource to operate on',
|
||||||
},
|
},
|
||||||
...calendarOperations,
|
...calendarOperations,
|
||||||
...calendarFields,
|
...calendarFields,
|
||||||
|
@ -183,7 +186,7 @@ export class GoogleCalendar implements INodeType {
|
||||||
if (resource === 'calendar') {
|
if (resource === 'calendar') {
|
||||||
//https://developers.google.com/calendar/v3/reference/freebusy/query
|
//https://developers.google.com/calendar/v3/reference/freebusy/query
|
||||||
if (operation === 'availability') {
|
if (operation === 'availability') {
|
||||||
const timezone = this.getTimezone();
|
const timezone = moment.tz.guess();
|
||||||
const calendarId = this.getNodeParameter('calendar', i) as string;
|
const calendarId = this.getNodeParameter('calendar', i) as string;
|
||||||
const timeMin = this.getNodeParameter('timeMin', i) as string;
|
const timeMin = this.getNodeParameter('timeMin', i) as string;
|
||||||
const timeMax = this.getNodeParameter('timeMax', i) as string;
|
const timeMax = this.getNodeParameter('timeMax', i) as string;
|
||||||
|
@ -191,8 +194,8 @@ export class GoogleCalendar implements INodeType {
|
||||||
const outputFormat = options.outputFormat || 'availability';
|
const outputFormat = options.outputFormat || 'availability';
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
timeMin: moment.tz(timeMin, timezone).utc().format(),
|
timeMin: options.timezone ? moment.tz(timeMin, options.timezone as string).utc(true).format() : timeMin,
|
||||||
timeMax: moment.tz(timeMax, timezone).utc().format(),
|
timeMax: options.timezone ? moment.tz(timeMax, options.timezone as string).utc(true).format() : timeMax,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
id: calendarId,
|
id: calendarId,
|
||||||
|
@ -237,6 +240,8 @@ export class GoogleCalendar implements INodeType {
|
||||||
'additionalFields',
|
'additionalFields',
|
||||||
i,
|
i,
|
||||||
) as IDataObject;
|
) as IDataObject;
|
||||||
|
const timezone = (additionalFields.timezone as string);
|
||||||
|
|
||||||
if (additionalFields.maxAttendees) {
|
if (additionalFields.maxAttendees) {
|
||||||
qs.maxAttendees = additionalFields.maxAttendees as number;
|
qs.maxAttendees = additionalFields.maxAttendees as number;
|
||||||
}
|
}
|
||||||
|
@ -248,12 +253,12 @@ export class GoogleCalendar implements INodeType {
|
||||||
}
|
}
|
||||||
const body: IEvent = {
|
const body: IEvent = {
|
||||||
start: {
|
start: {
|
||||||
dateTime: start,
|
dateTime: timezone ? moment.tz(start, timezone).utc(true).format() : start,
|
||||||
timeZone: additionalFields.timeZone || this.getTimezone(),
|
timeZone: timezone || moment.tz.guess(),
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
dateTime: end,
|
dateTime: timezone ? moment.tz(end, timezone).utc(true).format() : end,
|
||||||
timeZone: additionalFields.timeZone || this.getTimezone(),
|
timeZone: timezone || moment.tz.guess(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (additionalFields.attendees) {
|
if (additionalFields.attendees) {
|
||||||
|
@ -304,16 +309,17 @@ export class GoogleCalendar implements INodeType {
|
||||||
body.reminders.overrides = reminders;
|
body.reminders.overrides = reminders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.allday) {
|
if (additionalFields.allday) {
|
||||||
body.start = {
|
body.start = {
|
||||||
date: moment(start)
|
date: timezone ?
|
||||||
.utc()
|
moment.tz(start, timezone).utc(true).format('YYYY-MM-DD') :
|
||||||
.format('YYYY-MM-DD'),
|
moment.tz(start, moment.tz.guess()).utc(true).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
body.end = {
|
body.end = {
|
||||||
date: moment(end)
|
date: timezone ?
|
||||||
.utc()
|
moment.tz(end, timezone).utc(true).format('YYYY-MM-DD') :
|
||||||
.format('YYYY-MM-DD'),
|
moment.tz(end, moment.tz.guess()).utc(true).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//exampel: RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10;UNTIL=20110701T170000Z
|
//exampel: RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10;UNTIL=20110701T170000Z
|
||||||
|
@ -341,10 +347,12 @@ export class GoogleCalendar implements INodeType {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (additionalFields.repeatUntil) {
|
if (additionalFields.repeatUntil) {
|
||||||
|
const repeatUntil = timezone ?
|
||||||
|
moment.tz(additionalFields.repeatUntil as string, timezone).utc(true).format('YYYYMMDDTHHmmss') :
|
||||||
|
moment(additionalFields.repeatUntil as string).utc().format('YYYYMMDDTHHmmss');
|
||||||
|
|
||||||
body.recurrence?.push(
|
body.recurrence?.push(
|
||||||
`UNTIL=${moment(additionalFields.repeatUntil as string)
|
`UNTIL=${repeatUntil}Z`,
|
||||||
.utc()
|
|
||||||
.format('YYYYMMDDTHHmmss')}Z`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (body.recurrence.length !== 0) {
|
if (body.recurrence.length !== 0) {
|
||||||
|
@ -482,6 +490,8 @@ export class GoogleCalendar implements INodeType {
|
||||||
'updateFields',
|
'updateFields',
|
||||||
i,
|
i,
|
||||||
) as IDataObject;
|
) as IDataObject;
|
||||||
|
const timezone = (updateFields.timezone as string);
|
||||||
|
|
||||||
if (updateFields.maxAttendees) {
|
if (updateFields.maxAttendees) {
|
||||||
qs.maxAttendees = updateFields.maxAttendees as number;
|
qs.maxAttendees = updateFields.maxAttendees as number;
|
||||||
}
|
}
|
||||||
|
@ -494,14 +504,14 @@ export class GoogleCalendar implements INodeType {
|
||||||
const body: IEvent = {};
|
const body: IEvent = {};
|
||||||
if (updateFields.start) {
|
if (updateFields.start) {
|
||||||
body.start = {
|
body.start = {
|
||||||
dateTime: updateFields.start,
|
dateTime: timezone ? moment.tz(updateFields.start as string, timezone).utc(true).format() : updateFields.start as string,
|
||||||
timeZone: updateFields.timeZone || this.getTimezone(),
|
timeZone: timezone || moment.tz.guess(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (updateFields.end) {
|
if (updateFields.end) {
|
||||||
body.end = {
|
body.end = {
|
||||||
dateTime: updateFields.end,
|
dateTime: timezone ? moment.tz(updateFields.end as string, timezone).utc(true).format() : updateFields.end as string,
|
||||||
timeZone: updateFields.timeZone || this.getTimezone(),
|
timeZone: timezone || moment.tz.guess(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (updateFields.attendees) {
|
if (updateFields.attendees) {
|
||||||
|
@ -554,14 +564,14 @@ export class GoogleCalendar implements INodeType {
|
||||||
}
|
}
|
||||||
if (updateFields.allday && updateFields.start && updateFields.end) {
|
if (updateFields.allday && updateFields.start && updateFields.end) {
|
||||||
body.start = {
|
body.start = {
|
||||||
date: moment(updateFields.start as string)
|
date: timezone ?
|
||||||
.utc()
|
moment.tz(updateFields.start, timezone).utc(true).format('YYYY-MM-DD') :
|
||||||
.format('YYYY-MM-DD'),
|
moment.tz(updateFields.start, moment.tz.guess()).utc(true).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
body.end = {
|
body.end = {
|
||||||
date: moment(updateFields.end as string)
|
date: timezone ?
|
||||||
.utc()
|
moment.tz(updateFields.end, timezone).utc(true).format('YYYY-MM-DD') :
|
||||||
.format('YYYY-MM-DD'),
|
moment.tz(updateFields.end, moment.tz.guess()).utc(true).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//exampel: RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10;UNTIL=20110701T170000Z
|
//exampel: RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10;UNTIL=20110701T170000Z
|
||||||
|
@ -584,10 +594,12 @@ export class GoogleCalendar implements INodeType {
|
||||||
body.recurrence?.push(`COUNT=${updateFields.repeatHowManyTimes};`);
|
body.recurrence?.push(`COUNT=${updateFields.repeatHowManyTimes};`);
|
||||||
}
|
}
|
||||||
if (updateFields.repeatUntil) {
|
if (updateFields.repeatUntil) {
|
||||||
|
const repeatUntil = timezone ?
|
||||||
|
moment.tz(updateFields.repeatUntil as string, timezone).utc(true).format('YYYYMMDDTHHmmss') :
|
||||||
|
moment(updateFields.repeatUntil as string).utc().format('YYYYMMDDTHHmmss');
|
||||||
|
|
||||||
body.recurrence?.push(
|
body.recurrence?.push(
|
||||||
`UNTIL=${moment(updateFields.repeatUntil as string)
|
`UNTIL=${repeatUntil}Z`,
|
||||||
.utc()
|
|
||||||
.format('YYYYMMDDTHHmmss')}Z`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (body.recurrence.length !== 0) {
|
if (body.recurrence.length !== 0) {
|
||||||
|
@ -618,7 +630,7 @@ export class GoogleCalendar implements INodeType {
|
||||||
// Return the actual reason as error
|
// Return the actual reason as error
|
||||||
returnData.push(
|
returnData.push(
|
||||||
{
|
{
|
||||||
error: error.message,
|
error: (error as JsonObject).message,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue