Are there any plans to introduce Date/Time literals?

Brandon Benvie bbenvie at mozilla.com
Tue Oct 8 14:53:16 PDT 2013


On 10/8/2013 2:43 PM, Andrew Fedoniouk wrote:
> Quite often Date values are used in data exchanges in form of JS
> literals or JSON.
>
> It would be beneficial if JS (and JSON as derivative) will have an
> ability to represent dates literally  . For example:
>
> {
>     eventType: "meeting",
>     eventStarts: 2014-11-05T13:15:30Z,
>     eventDurationHours: 4
> }
>
> Technically we can allow date/time format using ISO 8601 as it is.
> That will require some additional look-ahead in tokenizer but is
> doable as far as I can tell.
>
> There are other options of course. Just wanted to know if this makes
> sense in principle.

While not exactly what you want, something close can be achieved using a 
tagged template:

```js
let date = ([string]) => Date.parse(string);

({
    eventType: "meeting",
    eventStarts: date`2014-11-05T13:15:30Z`,
    eventDurationHours: 4
})
```


More information about the es-discuss mailing list