I'm using Meteor to create an appointments app. I need to return the appointments for the chosen day.
Here's my data structure
{ "lastname" : "adsads", "firstname" : "adsadsads", "time" : "12:00 PM", "notes" : "adsadsads", "length" : 15, "date" : ISODate("2014-08-31T00:00:00Z"), "createdAt" : ISODate("2014-08-31T04:02:12.367Z"), "_id" : "gTxgn5ysRBYCros9z" }
Query code:
console.log("Starting query build.")
var theDate = Session.get("date");
console.log(theDate);
startDate = moment(theDate).zone(-12).startOf("day")._d;
console.log(startDate);
endDate = moment(theDate).zone(-12).endOf("day")._d;
console.log(endDate);
queryPointer = appointmentList.find({date: {$gte: startDate, $lt: endDate}})
console.log(queryPointer.fetch());
I use ._d to extract the internal Date object from moment. getDate() transforms the Date to UTC before returning. I know this is bad practise, storing dates in local time, but I did it as an attempt to get this damned thing working. I will switch back to UTC if I can find the root cause.
Stringified query:
"{"date":{"$gte":"2014-08-31T00:00:00.000Z","$lt":"2014-08-31T23:59:59.999Z"}}"
Console output:
"Starting query build." appointmentViewer.js:13
Date 2014-08-31T01:00:00.000Z appointmentViewer.js:15
Date 2014-08-31T00:00:00.000Z appointmentViewer.js:17
Date 2014-08-31T23:59:59.999Z appointmentViewer.js:19
Array [ ]
Thanks in advance for any assistance!