Hi! I don't know if it is already resolved but while inspecting the source code for a small project of mine, I saw that, when using the "j" format option, the result was way off.
When I looked at the function, I saw something that might be the cause.
Original function :
function date_get_day_of_the_year (date) { var now = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); var then = new Date(date.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / 24 * 60 * 60 * 1000); }
Proposed fix :
function date_get_day_of_the_year (date) { var now = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); var then = new Date(date.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / (24 * 60 * 60 * 1000)); }
Because with the priority of operations, the formula does time / 24, then 60 60 * 1000.
Hi! I don't know if it is already resolved but while inspecting the source code for a small project of mine, I saw that, when using the "j" format option, the result was way off.
When I looked at the function, I saw something that might be the cause.
Original function :
function date_get_day_of_the_year (date) { var now = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); var then = new Date(date.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / 24 * 60 * 60 * 1000); }
Proposed fix :
function date_get_day_of_the_year (date) { var now = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); var then = new Date(date.getFullYear(), 0, 0, 0, 0, 0); var time = now - then; return Math.floor(time / (24 * 60 * 60 * 1000)); }
Because with the priority of operations, the formula does time / 24, then 60 60 * 1000.
Hope this helps,
Kevin