I'm using Luxon.js to handle Date and I'm trying to parse some ISO string which comes from the server. It has this format
2019-04-04T12:12:07+03:00
and I'm using Luxon's method - fromISO which should parse this str
DateTime.fromISO("2019-04-04T12:12:07+03:00", "dd LLLL yyyy")
I'm expect to see 04 April 2019 - 15:12 in output but it returns 04 April 2019 - 12:12 somehow and I can't understand why it happens?
Am I doing something wrong? because when I'm trying to use this ISO string 2019-04-04T12:12:07.756Z it works like a charm. But I don't understand why the previous one isn't working and what should I do to make it working?
I'll appreciate any help!
P.S. to be honest, I have some gaps of my knowledge about ISO time so sorry if the question is stupid.
2019-04-04T12:12:07+03:00
says "in a zone with an offset of +3, it is 12:12". It isn't telling Luxon to add 3 hours; it's providing the context in which the time was expressed. For example, because zones whose offset is +3 have local times 3 hours ahead of UTC (that's what it means), then in England it's 9:12. The point is that it's a specific time on the planet, and the +3 is just telling you what rule was used in turning that time into a string.
Luxon takes in all that information and figures out what time it really is, which in its conception of time is the number of milliseconds that have transpired since the beginning of 1970 in UTC. It can then translate that into any zone's local time. Of course, if your computer is in a zone whose offset is +3, then that local time is 12:12:
-> TZ=Europe/Moscow node
> DateTime = require("luxon").DateTime
[Function: DateTime]
> var dt = DateTime.fromISO("2019-04-04T12:12:07+03:00")
undefined
> dt.toLocaleString(DateTime.TIME_24_SIMPLE)
'12:12'
My computer is actually on the US east coast, so I see a very different local time:
-> node
> DateTime = require("luxon").DateTime
[Function: DateTime]
> var dt = DateTime.fromISO("2019-04-04T12:12:07+03:00")
undefined
> dt.toLocaleString(DateTime.TIME_24_SIMPLE)
'05:12'
That's because my offset is -4, which means the local time here is 7 hours earlier than the +3 in the original string.
With my computer in any zone, I could of course tell Luxon to express the date in any other zone:
> dt.toUTC().toLocaleString(DateTime.TIME_24_SIMPLE)
'09:12'
> dt.setZone("Europe/Moscow").toLocaleString(DateTime.TIME_24_SIMPLE)
'12:12'
> dt.setZone("Asia/Tokyo").toLocaleString(DateTime.TIME_24_SIMPLE)
'18:12'