espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.76k stars 741 forks source link

wrong result function get.Month() #2307

Closed dapgo closed 1 year ago

dapgo commented 1 year ago

Today the function getMonth() is returning 11

Other Date functions are giving the expected result (12)

//lines with commands pasted on CLI Date.now(); require("locale").date(new Date(),1); require("locale").date(new Date(),0); getTime(); var x=new Date(); var y=x.getFullYear(); var m=x.getMonth(); var m=x.getMonth(); var d=x.getDay();

ide

mariusGundersen commented 1 year ago

This is working as expected, see https://stackoverflow.com/a/41992352

gfwilliams commented 1 year ago

Yes, they are zero based. It's just one of the joys of JS.

Always worth checking on a desktop JS implementation before blaming Espruino ;)

dapgo commented 1 year ago

Yes, they are zero based. It's just one of the joys of JS.

Always worth checking on a desktop JS implementation before blaming Espruino ;)

lesson learnt!

embarrased amateur developer wanting to remove the issue xD

Yes, I should have checked in a browser, but as the year was correct i though that i was a bug... In fact, now I realize that probably I faced similar behaviors long time ago in other language.

firefoxconsole

gfwilliams commented 1 year ago

Oh yes, and getDay isn't the day of the month, it's day of week. Sometimes (in fact most of the time) I wonder what the JS spec developers were even thinking :)