Firefox toLocaleDateString off by one day usually but not always

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Firefox toLocaleDateString off by one day usually but not always

Marfaba Stewart
In the Firefox console

new Date(2021,12,31) I see
"Date Mon Jan 31 2022 00:00:00 GMT -600 (CST)

but new Date(2021,12,31).toLocaleDateString() yields
"1/30/2022"

so it appears the day of the month has been decremeted
from 31 to 30.

This happens for me in any tab unless I open the
Preferences tab. In that tab, in the console output,
I get the expected
"1/31/2022"

This has been occurring for a long time on
Firefox for me on -current on at least two
OpenBSD boxes running
Firefox updated with pkg_add -D snap -u

The reason it's a problem is a browser
password manager displaying a credit card
date will decrement the month. For example,
if an expiration date of 01/21 for January 2021
is stored in the password manager, then the
browser extension displays 12/20.

This happens even if I display the browser
extension's data while in the Firefox
preferences tab.

I have been informed by the extension developers
that the browser, and not their extension, handles
the date. I've only noticed the problem on
my OpenBSD boxes and not on other operating
systems.

I've tried changing the language and unchecking
the "use operating system preferences" box in
Firefox preferences.

I see there was an old bug that has been resolved
in LocaleDateString that caused these off-by-one
errors, but I am guessing it's something else since
the correct date is displayed sometimes -- only
when I use the web developer console in a tab
used by Firefox Preferences.

Creating new profiles, clearing the cache, etc. has
had no effect.

Currently running OpenBSD 6.9-beta (GENERIC.MP)
#449: Sun Apr 4 00:53:21 MDT 2021
[hidden email]:/usr/src/sys/arch/
amd64/compile/GENERIC.MP

and
Firefox 87.0 (64-bit).

Reply | Threaded
Open this post in threaded view
|

Re: Firefox toLocaleDateString off by one day usually but not always

Greg Steuck-5
This is a wrong forum, but since I bothered to look this up...

Marfaba Stewart <[hidden email]> writes:

> In the Firefox console
>
> new Date(2021,12,31) I see
> "Date Mon Jan 31 2022 00:00:00 GMT -600 (CST)
>
> but new Date(2021,12,31).toLocaleDateString() yields
> "1/30/2022"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date
has this to say:

new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]])
...
monthIndex
  Integer value representing the month, beginning with 0 for January to 11 for December.

12 is out of range and so behaves unexpectedly.

> so it appears the day of the month has been decremeted
> from 31 to 30.
>
> This happens for me in any tab unless I open the
> Preferences tab. In that tab, in the console output,
> I get the expected
> "1/31/2022"

AFAICT, chrome behaves identically:

> new Date(2021,12,31)
Mon Jan 31 2022 00:00:00 GMT-0800 (Pacific Standard Time)
> new Date(2021,12,31).toLocaleDateString()
"1/31/2022"

Thanks
Greg