Skip to content

Instantly share code, notes, and snippets.

@amirnissim
Last active December 27, 2015 05:48
Show Gist options
  • Save amirnissim/7276380 to your computer and use it in GitHub Desktop.
Save amirnissim/7276380 to your computer and use it in GitHub Desktop.
JS dates gotcha when using ternary comparison
now = new Date()
// Sat Nov 02 2013 08:56:45 GMT+0200 (IST)
start = new Date()
start.setMonth(start.getMonth()-1)
start
// Wed Oct 02 2013 08:57:26 GMT+0300 (IDT)
end = new Date()
end.setDate(end.getDate()-1)
// Fri Nov 01 2013 08:57:30 GMT+0200 (IST)
start < now
// true
now < end
// false
start < now < end
// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment