Skip to content

Commit fcd107a

Browse files
committed
Add 3rd-party date formatter for display patterns
1 parent 6530617 commit fcd107a

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@fortawesome/free-solid-svg-icons": "^6.2.1",
7272
"axios": "^1.2.1",
7373
"codemirror": "^6.0.1",
74+
"dateformat": "^5.0.3",
7475
"delay": "^6.0.0",
7576
"dotenv": "^16.3.1",
7677
"eslint4b-prebuilt": "^6.7.2",

src/lib/components/Table/shared.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dateFormat from 'dateformat';
2+
13
import type { FilterOptionsEnum } from '$models/Enums';
24
import type { Columns, Filter, ServerColumn } from '$models/Models';
35

@@ -115,14 +117,13 @@ export const convertServerColumns = (columns: ServerColumn[]) => {
115117
columns.forEach((col) => {
116118
let instructions = {};
117119

118-
// if (col.instructions?.displayPattern) {
119-
// instructions = {
120-
// toStringFn: (date: Date) =>
121-
// date.toLocaleString('en-US', col.instructions?.displayPattern || {}),
122-
// toSortableValueFn: (date: Date) => date.getTime(),
123-
// toFilterableValueFn: (date: Date) => date
124-
// };
125-
// }
120+
if (col.instructions?.displayPattern) {
121+
instructions = {
122+
toStringFn: (date: Date) => dateFormat(date, col.instructions?.displayPattern || ''),
123+
toSortableValueFn: (date: Date) => date.getTime(),
124+
toFilterableValueFn: (date: Date) => date
125+
};
126+
}
126127

127128
if (col.instructions?.missingValues) {
128129
instructions = {

0 commit comments

Comments
 (0)