Skip to content

Commit f97295b

Browse files
feat: enable {{now}} placeholder for datetime fields in edition (#1200)
1 parent e2b1276 commit f97295b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/const/placeholders.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ export const isUsingTodayPlaceholder = (value: any) => {
3030
);
3131
};
3232

33+
/**
34+
* Tests whether value is using the {{now}} placeholder
35+
*
36+
* @param value value to test
37+
* @returns true if using {{now}}
38+
*/
39+
export const isUsingNowPlaceholder = (value: any) => {
40+
return value === Placeholder.NOW;
41+
};
42+
3343
/**
3444
* Extract string contained into brackets used for placeholders.
3545
*

src/utils/filter/getDateForMongo.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
REGEX_TODAY_PLUS,
44
REGEX_TODAY_MINUS,
55
isUsingTodayPlaceholder,
6+
isUsingNowPlaceholder,
67
} from '../../const/placeholders';
78

89
/**
@@ -17,6 +18,7 @@ export const getDateForMongo = (
1718
// today's date
1819
let startDate: Date;
1920
if (isUsingTodayPlaceholder(value)) {
21+
// Using {{today}}
2022
startDate = new Date();
2123
startDate.setHours(0, 0, 0, 0);
2224
// today + number of days
@@ -31,8 +33,12 @@ export const getDateForMongo = (
3133
extractStringFromBrackets(value).split('-')[1]
3234
);
3335
startDate.setDate(startDate.getDate() + difference);
34-
} // classic date
36+
}
37+
} else if (isUsingNowPlaceholder(value)) {
38+
// Using {{now}}
39+
startDate = new Date();
3540
} else {
41+
// Other dates
3642
startDate = new Date(value);
3743
}
3844
const endDate = new Date(startDate);

0 commit comments

Comments
 (0)