From 21936c88a84b8c03a8d02391cb7112b0e4d9f1f9 Mon Sep 17 00:00:00 2001 From: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:44:35 +0100 Subject: [PATCH] fix(YouTube Node): Fix Date filters (#10725) --- .../nodes/Google/YouTube/YouTube.node.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts b/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts index b406e13a4b294..07de1d36fac4a 100644 --- a/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts +++ b/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts @@ -10,6 +10,7 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType, BINARY_ENCODING, NodeOperationError } from 'n8n-workflow'; +import { DateTime } from 'luxon'; import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions'; import { channelFields, channelOperations } from './ChannelDescription'; @@ -762,6 +763,28 @@ export class YouTube implements INodeType { qs.type = 'video'; qs.forMine = true; + if (filters.publishedAfter) { + const publishedAfter = DateTime.fromISO(filters.publishedAfter as string); + if (publishedAfter.isValid) { + filters.publishedAfter = publishedAfter.setZone(this.getTimezone()).toISO(); + } else { + throw new NodeOperationError( + this.getNode(), + `The value "${filters.publishedAfter as string}" is not a valid DateTime.`, + ); + } + } + if (filters.publishedBefore) { + const publishedBefore = DateTime.fromISO(filters.publishedBefore as string); + if (publishedBefore.isValid) { + filters.publishedAfter = publishedBefore.setZone(this.getTimezone()).toISO(); + } else { + throw new NodeOperationError( + this.getNode(), + `The value "${filters.publishedBefore as string}" is not a valid DateTime.`, + ); + } + } Object.assign(qs, options, filters);