question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chrome v88 (88.0.4324.93) for Android does not recognize date

See original GitHub issue

Device: Android phone (with Android v10) Browser: Chrome v88 (88.0.4324.93).

dayJs(‘2021-01-26T00:00:00Z’).tz(tz) returns “Invalid Date”. Started happening with Chrome upgrade v88.

dayJs(dateWithFormat).tz(tz) --> Works everywhere except Chrome88 on Android 10 dayJs.tz(dateWithFormat, tz) --> Works on Chrome 88 for Android 10.

Shouldn’t these methods return the same values irrespective of the browser or the underlying OS?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
janousekcommented, Jan 28, 2021

I wrote this polyfill to fix this issue. It is really ugly, but it should work.

// Chrome toLocaleString bug
(() => {
    let testDate = new Date(2021, 0, 17, 20, 16, 51);
    if (Intl?.DateTimeFormat != null) {
        let str = testDate.toLocaleString('en-US');
        if (str.indexOf('PM') == -1 || Number.isNaN(new Date(str).valueOf())) {
            if (new Intl.DateTimeFormat('cs-CZ').formatToParts != null) {


                let original = Date.prototype.toLocaleString;
                Date.prototype.toLocaleString = function (locale, opts) {
                    if (locale != 'en-US' || opts == null || Object.keys(opts).length != 1) {
                        return original.call(this, locale, opts);
                    }

                    let format = new Intl.DateTimeFormat('cs-CZ', {
                        year: 'numeric',
                        month: 'numeric',
                        day: 'numeric',
                        hour: 'numeric',
                        minute: 'numeric',
                        second: 'numeric',
                        hour12: false,
                        timeZone: opts.timeZone
                    });
                    let parts = format.formatToParts(this);
                    let component = (type) => {
                        return parseInt(parts.filter(x => x.type == type)[0].value, 10);
                    };
                    return new Date(component('year'), component('month') - 1, component('day'), component('hour'), component('minute'), component('second')).toISOString();
                };
            }
        }
    }
})();

Notice: This code is only usable if you do not use “toLocaleString” anywhere, except dayjs. It just fix dayjs, but can break other code (if it use toLocaleString method).

3reactions
romanlexcommented, Jan 26, 2021

Looks like chrome started to ignore locale in arguments ECMA-402 image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome for Android Update - Chrome Releases
We've just released Chrome 88 (88.0.4324.93) for Android: it'll become available on Google Play over the next few weeks.
Read more >
We are facing issue on Android mWeb Chrome/88.0.4324. js new ...
We are facing issue happen on Android mobile browser chrome/88.0.4324.93 or chrome/88.0.4324.141. Our customers are getting wrong date while run our ...
Read more >
Chrome 88 brings better password protection and Incognito ...
Android Police · Chrome 88 brings better password protection and Incognito screenshots while sunsetting Flash (APK Download).
Read more >
Google Chrome: Fast & Secure 88.0.4324.93 - APKMirror
Google Chrome: Fast & Secure 88.0.4324.93 APK Download by Google LLC ... Consult our handy FAQ to see which download is right for...
Read more >
How to Update Chrome to the Latest Version - Google Chrome
If you haven't closed your browser in a while, you might see a pending update. If an update is pending, the icon will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found