Skip to content

Commit 1d3b44a

Browse files
committed
Add formatDate function to calcFunctions
1 parent c671f45 commit 1d3b44a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

libs/shared/src/lib/utils/parser/calcFunctions.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatDate } from '@angular/common';
12
import { ceil, floor, round } from 'lodash';
23

34
/**
@@ -90,6 +91,26 @@ const calcFunctions: Record<
9091
return percent.toFixed(parsedPrecision) + '%';
9192
},
9293
},
94+
formatDate: {
95+
signature: 'formatDate( value ; format)',
96+
/**
97+
* Format a date
98+
*
99+
* @param value The date to format
100+
* @param format The format to use (optional, default to 'mediumDate')
101+
* @param locale The locale to use (optional, default to the user browser locale)
102+
* @param timezone The timezone to use (optional, default to the user browser timezone)
103+
* @returns The formatted date
104+
*/
105+
call: (
106+
value,
107+
format = 'mediumDate',
108+
locale = Intl.DateTimeFormat().resolvedOptions().locale, // could also be navigator.language
109+
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
110+
) => {
111+
return formatDate(value, format, locale, timezone);
112+
},
113+
},
93114
};
94115

95116
export default calcFunctions;

0 commit comments

Comments
 (0)