Sugar
Sugar copied to clipboard
`now` with `fromUTC:true` creates date without time
I expected Date.create('now', {fromUTC:true}).toISOString()
to be 2017-01-31T16:17:43.385Z
but instead it was 2017-01-31T00:00:00.000Z
. The time does not exist and is only with when setting fromUTC:true
.
I added some tests and was going to submit a pull request but I realized I maybe missing something and this might be on purpose when reading this comment. https://github.com/andrewplummer/Sugar/blob/master/lib/date.js#L1502
Is this expected behavior or a bug?
In the meantime, I can check for the input and switch fromUTC
to false
when now
as the flag does not change anything in this case.
Hello, sorry to take so long to respond to this. I'm having a look at it now and the resetting the time is definitely a bug, but there is some other ambiguity to be considered. The fact that you are using fromUTC
with "now" might suggest that you are expecting it to do something different, but I would argue that this shouldn't be the case. fromUTC
should be expected to parse numbers as UTC time, however "now" is a moment that exists irrespective to timezones, and so shouldn't return anything other than the exact millisecond when the date is created.
Just want to make sure we're on the same page here...
I just ran into this use case. I am also not sure if this is an expected behavior or a bug, but at least @shepherdsam workaround worked for me too.
@andrewplummer Yes, we are on the same page. You are right in that it doesn't make sense for now
to have the fromUTC:true
flag. In my case, I was taking something a user typed freeform and passing it through this function.
@eruizdechavez Glad it was helpful!