I need to capture a date value, parse it to an ISODate and then query a mongoDB collection that stores an object with a date value. The query checks for equality between the date of an event and matches it against a function that determines if the date will fall on a weekend. Everything works, however if the date falls on a Monday, it will also come through on the results.
Something I have noticed is the date object moves back a day when we use toISOString:
Date Obj
Mon Apr 18 2016 00:00:00 GMT+0100 (BST)
toISOString:
2016-04-17T23:00:00.000Z
Notice it now has the 17th as the date?
This inconsistency exists in the DB as well:
{
"_id" : ObjectId("56fe91afceb044f551dbffce"),
"url" : "http://www.timeoutshanghai.com/features/Blog-Food__Drink/35271/Baristas-showcase-latte-art-in-Shanghai.html",
"title" : "Baristas showcase latte art in Shanghai - Blog - Time Out - Shanghai",
"selectedDate" : ISODate("2016-04-17T23:00:00Z"),
"__v" : 0
}
This should give selectedDate" : ISODate("2016-04-17T23:00:00Z")
However if we log the collection to the console, the date is returned as a Monday:
{ _id: 56fe91c5ceb044f551dbffcf,
url: 'http://www.timeoutshanghai.com/features/Blog-Food__Drink/35271/Baristas-showcase-latte-art-in-Shanghai.html',
title: 'Baristas showcase latte art in Shanghai - Blog - Time Out - Shanghai',
selectedDate: Mon Apr 18 2016 00:00:00 GMT+0100 (BST),
__v: 0 },
This becomes an issue when I query the DB to only return events on a weekend as the Monday's are slipping through.
BST. Midnight on day X in BST is 23:00 on day X-1 in UTC (GMT). It's just a time zone difference.