nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker
BSD Zero Clause License
616 stars 191 forks source link

Small bug in the date_get_day_of_the_year function #197

Closed kekegt closed 6 years ago

kekegt commented 6 years ago

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

nazar-pc commented 6 years ago

Nice catch, thanks! Fixed in 3.1.2