Hi, great work with Luxon, i tried playing with it today
I'm not sure if i'm doing something wrong here but..
const moment = require('moment');
let mm = moment('2017-11-18 12:47:20.684054+00:00');
console.log(mm);
Works fine, however
const DateTime = require('luxon').DateTime;
let dt = DateTime.fromString('2017-11-18 12:47:20.684054+00:00');
console.log(dt)
Fails with:
/Users/willij87/workspace/ella2/node_modules/luxon/build/cjs/luxon.js:3052
for (var i = 0; i < fmt.length; i++) {
^
TypeError: Cannot read property 'length' of undefined
Is this a known issue? Im not sure which format that timestamp is in, but luxon doesn't seem happy with it, fromISO didn't give much better results either :/
A few things going on here:
fromISO won't accept it without the T because AFAIK, it's not really an ISO format.fromISO's handling of additional decimal places, which you're also using.So: grab the latest Luxon (0.0.20 is hot off the presses), replace your space with a T, and use fromISO:
DateTime.fromISO('2017-11-18 12:47:20.684054+00:00'.replace(' ', 'T'))
I'll work on the error message for fromString.
Amazing response, thank you very much.
If you're interested, that timestamp comes from Postgresql 9.5, its the "timestamp with time zone" type
https://www.postgresql.org/docs/9.5/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
@icambron is there a seperate standard for SQL dates?
I tried to find if they follow a standard but couldn't come up with anything, https://www.postgresql.org/docs/9.5/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
Ah, right, SQL dates.
https://www.ibm.com/support/knowledgecenter/en/SSGU8G_12.1.0/com.ibm.esqlc.doc/ids_esqlc_0190.htm
I'd be willing to add support to this to Luxon. I'll write up a ticket.
Great!
I can imagine a lot of people will be putting SQL timestamps straight into luxon, so it would be useful
In case anyone ends up here: Luxon now has fromSQL()
Most helpful comment
In case anyone ends up here: Luxon now has
fromSQL()