helpers / helper-date

Format dates with date.js and moment.js. Uses date.js to parse human readable date phrases, and moment to format the rendered output. Should work with any Handlebars, Lo-Dash, underscore, or any template engine that allows helper functions to be registered. Also compatible with verb, assemble and Template.
MIT License
6 stars 10 forks source link

helper-date returns invalid date in some cases when used with handlebars #9

Closed prashantagarwal closed 4 years ago

prashantagarwal commented 4 years ago

I was using helper-date with handlebars but in some scenarios, it is returning Invalid date.

Snippet to reproduce the issue: https://runkit.com/prashantagarwal272/5e7c445b54bf8c001adf1d9f

doowb commented 4 years ago

Hi @prashantagarwal ... the timestamp in your example is passed into date.js before passing to moment. This is to allow patterns like 5 years ago, as shown in the examples in the README.

In your example, if you add datejs=false, then the timestamps are formatted correctly because date.js is not being used:

{{date data.timestamp "D MMM, YYYY, h:mm a" datejs=false}}

I hope this helps. I'm going to close this issue, but let me know if you have the same issue after using datejs=false and I'll reopen it.