spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.99k stars 184 forks source link

Passing undefined, null, false, {} to spacetime returns current time #240

Closed rem4ik4ever closed 3 years ago

rem4ik4ever commented 3 years ago

Information

We recently ran into an issue where passing null, undefined values to spacetime was returning current time. I ran a few tests and it appears that passing undefined, null, false, {} have this behaviour.

Screen Shot 2020-11-12 at 1 26 31 PM

I wonder if that is intended behaviour?

spencermountain commented 3 years ago

hey Rem! yeah, this is a good observation, and something we should tighten-up. yeah, null and undefined were intentional, but the other ones are making me scratch my head.

Lemme think about this a bit. cheers

spencermountain commented 3 years ago

yeah, I figure false should behave like null and undefined.

'2011-11-33' is right to be invalid.

but {} and [] are both messed-up. They should return the same as null. thanks

jecraig commented 3 years ago

@spencermountain I've been wondering if a strict constructor flag would be useful so people can use it when they might not have the input fully sanitized.

rem4ik4ever commented 3 years ago

@spencermountain thanks for your response. We usually run our own validation to see if data we pass is indeed a valid date string or object. However there are times where data comes back from server as null and one would assume that it should be invalid however its not.

@jecraig I can see that as a useful feature.

spencermountain commented 3 years ago

empty [] and {} now return 'now' like null, false and undefined. released in 6.10.0. thanks!