Add difference helper

This commit is contained in:
Adria Navarro 2025-03-06 11:09:49 +01:00
parent 99fc3420fd
commit b075a34ed7
2 changed files with 10 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import dayjs from "dayjs"
import dayjs, { UnitType } from "dayjs"
import dayjsDurationPlugin from "dayjs/plugin/duration"
import dayjsAdvancedFormatPlugin from "dayjs/plugin/advancedFormat"
@ -133,3 +133,8 @@ export const duration = (str: any, pattern: any, format: any) => {
return duration.humanize()
}
}
export const difference = (from: string, to: string, units: UnitType) => {
const result = dayjs(new Date(from)).diff(dayjs(new Date(to)), units)
return result
}

View File

@ -1,7 +1,7 @@
// @ts-ignore we don't have types for it
import helpers from "@budibase/handlebars-helpers"
import { date, duration } from "./date"
import { date, difference, duration } from "./date"
import {
HelperFunctionBuiltin,
EXTERNAL_FUNCTION_COLLECTIONS,
@ -9,8 +9,9 @@ import {
import Handlebars from "handlebars"
const ADDED_HELPERS = {
date: date,
duration: duration,
date,
duration,
difference,
}
export const externalCollections = EXTERNAL_FUNCTION_COLLECTIONS