-
-
Notifications
You must be signed in to change notification settings - Fork 453
Closed
Description
This relates to #392
While there are helpers to generate a random date and format it like date, when the date generation has to be more custom, there is currently no good way to then format it. (There is actually dateTimeShift that can be used for this, but it is not very intuitive).
Proposition
Add a dateFormat helper that would work like this :
{{dateFormat '2022-02-01' 'YYYY'}}
And output :
2022
Motivation
In order to emulate one of our services, I need to generate a list of every date of the current month up until the current day.
I have managed this with :
[
{{#each (array 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1)}}
{{dateTimeShift date=(now (concat "YYYY-MM-'" (substr (concat '0' @this) -2) "")) format='T'}},
{{#unless @last}},{{/unless}}
{{/each}}
]
which is hacky but good enough.
We can see that I have to use dateTimeShift, but I don't provide any "shift", because I only use it to format the date that I generate.
With a dateFormat helper, it would become :
[
{{#each (array 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1)}}
{{dateFormat (now (concat "YYYY-MM-'" (substr (concat '0' @this) -2) "")) 'T'}},
{{#unless @last}},{{/unless}}
{{/each}}
]
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
✅ Done (ready for next release)