phstc/jquery-dateFormat

Time formatting stopped working with Chrome on Mac

trevoriancox opened this issue · 6 comments

I'm using Chrome 67.0.3396.99 on macOS High Sierra. The code has worked for a long time on many instances of Chrome on Windows, ChromeOS, and macOS. It still does work on all these OS's except on my development mac.

Just recently,
'HH:mm:ss a ddd MMMM d yyyy' started formatting a date and time as: 00:00:00 AM Monday July 9 2018,

and ddd MMMM d yyyy, h:mm:ss a as Monday July 9 2018 NaN:00:00 AM.

I have logged the datetime object I am passing, simply new Date(), and it does have a time, e.g. Mon Jul 09 2018 12:01:28 GMT-0400.

I have tried updating to the latest github code but the issue was not resolved.

📌 #115

phstc commented

Hi @trevoriancox

I added a test case for both 1db754b and it seems to be working fine.

Can you create a JSFiddle so I can try to reproduce on my development mac?

I also have this behaviour on Android Chrome v67 confirmed on multiple devices.
I do not see the issue on Chrome v67 Mac High Sierra

phstc commented

Can you create a JSFiddle so I can try to reproduce on my development mac?

I created a JSFiddle example based on this test case I created to try to reproduce this issue and I couldn't reproduce it. I ran the JSFiddle on an Android device and it worked fine.

Could you create a JSFiddle with the failing example, so I can try to reproduce it myself?

Here is my code. With the latest jquery-dateformat 28-04-2018, I get NaN for hour. With an old "1.0" from cdnjs, the time is always 12:00:00 AM.

Again this is only on one Mac with Chrome. Safari is OK, as are other devices.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
/*! jquery-dateformat 28-04-2018 */
...
</script>
<script>
  var now = (new Date()).getTime();
  document.write($.format.date(now, 'h:mm:ss a'));
</script>

I think I may have found the cause of this issue.

The time is analysed by splitting into a string using colon for delimiter and testing for length == 3. Some browsers insert an additional colon in the time zone definition e.g. (GMT +01:00). This causes the length == 3 to be false and the time is not parsed resulting in a zero value.

This happens around line 68:

`

  timeArray = time.split(':');

  if(timeArray.length === 3) {`

etc

phstc commented

@weblaunch could you send me a sample string that fails? I added this test case, but I couldn't reproduce the problem.

/me wishes he had documented this better