Keeping in mind DST, Leaps, Timezones.
Can this function ever screw things up? It must take a unix epoch (GMT) and figure out the exact calendar day of that epoch and return the epoch at 12:00AM of that day.
function convertToDayStartTime(epoch) {
var d = new Date(0);
d.setUTCSeconds(epoch);
var dayStart = new Date(d.toDateString()).getTime()/1000;
return dayStart;
}
For example:
expect(convertToDayStartTime(1378000800)).toEqual(1377993600);
EDIT:
Looks like it is a bit screwed up. Following test fails:
expect(convertToDayStartTime(1377993599)).toEqual(1377907200);
I am not sure how to fix.
12:00 AMlocal time or GMT?