Add date difference calculation functionality (#10673)

* Add date difference calculation functionality

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>

* Fix

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>

* Fix formatting

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>

---------

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2026-03-24 00:49:55 +05:00
committed by GitHub
parent 6f14b3d73a
commit 31246a11a0
23 changed files with 258 additions and 44 deletions
@@ -246,6 +246,34 @@ export function Offset (val: Timestamp, props: Record<string, any>): Timestamp {
return val
}
export async function DateDifference (
value: Timestamp,
props: Record<string, any>,
control: ProcessControl,
execution: Execution
): Promise<number> {
if (typeof value !== 'number') return 0
const otherDate = await getContextValue(props.otherDate, control, execution)
if (typeof otherDate !== 'number') return 0
const diff = value - otherDate
const v = new Date(value)
const o = new Date(otherDate)
switch (props.unit) {
case 'hours':
return Math.floor(diff / (1000 * 60 * 60))
case 'weeks':
return Math.floor(diff / (1000 * 60 * 60 * 24 * 7))
case 'months':
return (v.getUTCFullYear() - o.getUTCFullYear()) * 12 + (v.getUTCMonth() - o.getUTCMonth())
case 'years':
return v.getUTCFullYear() - o.getUTCFullYear()
case 'days':
default:
return Math.floor(diff / (1000 * 60 * 60 * 24))
}
}
// #endregion
// #region Numbers
@@ -508,4 +536,3 @@ export function DayFromDate (value: Date): number {
}
// #endregion