mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
19 lines
574 B
TypeScript
19 lines
574 B
TypeScript
import { DateTime } from 'luxon';
|
|
import moment from 'moment';
|
|
import type { IExecuteFunctions } from 'n8n-workflow';
|
|
import { NodeOperationError } from 'n8n-workflow';
|
|
|
|
export function parseDate(this: IExecuteFunctions, date: string | DateTime, timezone: string) {
|
|
let parsedDate;
|
|
|
|
if (date instanceof DateTime) {
|
|
parsedDate = date;
|
|
} else {
|
|
parsedDate = DateTime.fromISO(moment.tz(date, timezone).toISOString());
|
|
if (parsedDate.invalidReason === 'unparsable') {
|
|
throw new NodeOperationError(this.getNode(), 'Invalid date format');
|
|
}
|
|
}
|
|
return parsedDate;
|
|
}
|