From f634f0dc59389a8c7ecd4154d2cf9af495b129aa Mon Sep 17 00:00:00 2001 From: Valya <68596159+valya@users.noreply.github.com> Date: Mon, 16 Jan 2023 13:01:58 +0000 Subject: [PATCH] fix: Extend date functions clobbering plus/minus (#5170) * fix: extended date functions clobbering plus/minus * fix: minus extension doing plus instead --- packages/workflow/src/Extensions/DateExtensions.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/workflow/src/Extensions/DateExtensions.ts b/packages/workflow/src/Extensions/DateExtensions.ts index a34238f1fb..6c6d0c2b78 100644 --- a/packages/workflow/src/Extensions/DateExtensions.ts +++ b/packages/workflow/src/Extensions/DateExtensions.ts @@ -5,6 +5,7 @@ import { DateTimeFormatOptions, DateTimeUnit, Duration, + DurationLike, DurationObjectUnits, LocaleOptions, } from 'luxon'; @@ -161,7 +162,11 @@ function isWeekend(date: Date): boolean { return [DAYS.saturday, DAYS.sunday].includes(DateTime.fromJSDate(date).weekday); } -function minus(date: Date | DateTime, extraArgs: unknown[]): Date { +function minus(date: Date | DateTime, extraArgs: unknown[]): Date | DateTime { + if (isDateTime(date) && extraArgs.length === 1) { + return date.minus(extraArgs[0] as DurationLike); + } + const [durationValue = 0, unit = 'minutes'] = extraArgs as [number, DurationUnit]; if (isDateTime(date)) { @@ -170,7 +175,11 @@ function minus(date: Date | DateTime, extraArgs: unknown[]): Date { return DateTime.fromJSDate(date).minus(generateDurationObject(durationValue, unit)).toJSDate(); } -function plus(date: Date | DateTime, extraArgs: unknown[]): Date { +function plus(date: Date | DateTime, extraArgs: unknown[]): Date | DateTime { + if (isDateTime(date) && extraArgs.length === 1) { + return date.plus(extraArgs[0] as DurationLike); + } + const [durationValue = 0, unit = 'minutes'] = extraArgs as [number, DurationUnit]; if (isDateTime(date)) {