mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Google Calendar Node): Next occurrence property in recurring events (#8444)
This commit is contained in:
@@ -12,12 +12,12 @@ import type {
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
import { RRule } from 'rrule';
|
||||
|
||||
export async function googleApiRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
@@ -128,3 +128,54 @@ export async function getTimezones(
|
||||
);
|
||||
return { results };
|
||||
}
|
||||
|
||||
type RecurentEvent = {
|
||||
start: {
|
||||
dateTime: string;
|
||||
timeZone: string;
|
||||
};
|
||||
end: {
|
||||
dateTime: string;
|
||||
timeZone: string;
|
||||
};
|
||||
recurrence: string[];
|
||||
nextOccurrence?: {
|
||||
start: {
|
||||
dateTime: string;
|
||||
timeZone: string;
|
||||
};
|
||||
end: {
|
||||
dateTime: string;
|
||||
timeZone: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export function addNextOccurrence(items: RecurentEvent[]) {
|
||||
for (const item of items) {
|
||||
if (item.recurrence) {
|
||||
const rrule = RRule.fromString(item.recurrence[0]);
|
||||
const until = rrule.options?.until;
|
||||
|
||||
const now = new Date();
|
||||
if (until && until < now) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const nextOccurrence = rrule.after(new Date());
|
||||
item.nextOccurrence = {
|
||||
start: {
|
||||
dateTime: moment(nextOccurrence).format(),
|
||||
timeZone: item.start.timeZone,
|
||||
},
|
||||
end: {
|
||||
dateTime: moment(nextOccurrence)
|
||||
.add(moment(item.end.dateTime).diff(moment(item.start.dateTime)))
|
||||
.format(),
|
||||
timeZone: item.end.timeZone,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user