Open jcmerlin opened 6 years ago
You can provide a custom Date parser via DUK_USE_DATE_PARSE_STRING. See https://github.com/svaarala/duktape/blob/master/doc/datetime.rst#external-date-providers.
As for what's the best parser for parsing a wide variety of different formats, I don't have a recommendation for that. For Unix platforms Duktape automatically uses strptime() with %c:
%c The date and time representation for the current locale.
This works e.g. with:
duk> new Date('Sun Sep 23 17:27:23 2018')
= "2018-09-23T14:27:23.000Z"
But it comes down to the locale settings and strftime/strptime in the platform.
Thanks.
If you end up with a good solution which accepts a wide range of Date formats, it'd be nice to hear :)
@jcmerlin Any update on this issue?
You can run/embed moment.js
. Works fine.
Yeah, that's true - but it may not be a possible solution if the Date built-in specifically has to accept the locale specific formats (e.g. if you have an existing code base you don't control).
I have code that does this:
However, Duktape cannot parse this date correctly and creates an invalid
Date
object.I saw this issue: https://github.com/svaarala/duktape/issues/712 but I don't know what's the current status of it. Is it implemented, at least on Unix platforms? What'd be the best way to have this feature at least only for Unix platforms? Thanks