mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
21 lines
660 B
TypeScript
21 lines
660 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) {
|
|
console.log('date is a DateTime object');
|
|
parsedDate = date;
|
|
} else {
|
|
parsedDate = DateTime.fromISO(moment.tz(date, timezone).toISOString());
|
|
if (parsedDate.invalidReason === 'unparsable') {
|
|
console.log(parsedDate.invalidReason);
|
|
throw new NodeOperationError(this.getNode(), 'Invalid date format');
|
|
}
|
|
}
|
|
return parsedDate;
|
|
}
|