diff --git a/libs/shared/src/lib/utils/parser/calcFunctions.ts b/libs/shared/src/lib/utils/parser/calcFunctions.ts index b9e061d167..c9e4daa395 100644 --- a/libs/shared/src/lib/utils/parser/calcFunctions.ts +++ b/libs/shared/src/lib/utils/parser/calcFunctions.ts @@ -1,3 +1,4 @@ +import { formatDate } from '@angular/common'; import { ceil, floor, round } from 'lodash'; /** @@ -106,6 +107,26 @@ const calcFunctions: Record< } }, }, + formatDate: { + signature: 'formatDate( value ; format)', + /** + * Format a date + * + * @param value The date to format + * @param format The format to use (optional, default to 'mediumDate') + * @param locale The locale to use (optional, default to the user browser locale) + * @param timezone The timezone to use (optional, default to the user browser timezone) + * @returns The formatted date + */ + call: ( + value, + format = 'mediumDate', + locale = Intl.DateTimeFormat().resolvedOptions().locale, // could also be navigator.language + timezone = Intl.DateTimeFormat().resolvedOptions().timeZone + ) => { + return formatDate(value, format, locale, timezone); + }, + }, }; export default calcFunctions;