dygraphs icon indicating copy to clipboard operation
dygraphs copied to clipboard

Can't parse 1970-01-01T00:00:00.000Z as a date

Open analytophile opened this issue 6 months ago • 3 comments

Trying to plot a time series that uses the following ISO date stamp in Google Chrome: 1970-01-01T00:00:00.000Z

It returns the following error message: "Couldn't parse 1970-01-01T00:00:00.000Z as a date"

This works for any other date in the format yyyy-mm-ddT00:00:00.000Z

This is apparently a known issue in js on different browsers: https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results

It can be recreated by providing the following data object to a new dygraph plot. If the problematic date is the first in the time series, it does not draw a plot. If it is in the middle, it just skips plotting that data point

Date,Data 1969-12-31T00:00:00.000Z,5.44 1970-01-01T00:00:00.000Z,5.35 1970-01-02T00:00:00.000Z,5.18

analytophile avatar Jun 19 '25 16:06 analytophile

On Thu, 19 Jun 2025, James Craig wrote:

analytophile created an issue (danvk/dygraphs#1062)

Trying to plot a time series that uses the following ISO date stamp in Google Chrome: 1970-01-01T00:00:00.000Z

It returns the following error message: "Couldn't parse 1970-01-01T00:00:00.000Z as a date"

This works for any other date in the format yyyy-mm-ddT00:00:00.000Z

This is apparently a known issue in js on different browsers: https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results

Interesting, but not related.

I’m looking for it, as I have an idea.

I found this… riddle me this:

dateStrSlashed = dateStr.replace("-", "/", "g");
while (dateStrSlashed.search("-") != -1) {
  dateStrSlashed = dateStrSlashed.replace("-", "/");
}

Should the first line not obsolete the other three?

mirabilos avatar Jun 19 '25 18:06 mirabilos

On Thu, 19 Jun 2025, James Craig wrote:

It can be recreated by providing the following data object to a new dygraph plot.

CSV only, but yes.

For now, please apply the following patch locally:

Change lines…

518 if (d && !isNaN(d)) return d; and 533 if (!d || isNaN(d)) {

… to…

518 if (d != null && !isNaN(d)) return d; and 533 if (d == null || isNaN(d)) {

… (yes, that is != and ==, NOT !== and ===).

This should fix your issue.

Before I commit this, a question to the original author:

@danvk I read about some framework returning null instead of NaN on invalid dates (hence the check above, also catching undefined), but is there ever a chance for dateStrToMillis to return 0 for invalid dates, and if so, does the environment do it consistently (i.e. could we check if dateStrToMillis("invalid") === 0 and if so, compare for 0 as well, if not don’t)? Or might even be better to just let 0 always pass, and it’ll complain if the axis is unsorted.

Thanks, //mirabilos

FWIW, I'm quite impressed with mksh interactively. I thought it was much much more bare bones. But it turns out it beats the living hell out of ksh93 in that respect. I'd even consider it for my daily use if I hadn't wasted half my life on my zsh setup. :-) -- Frank Terbeck in #!/bin/mksh

mirabilos avatar Jun 19 '25 18:06 mirabilos

thanks for the fix!

analytophile avatar Sep 05 '25 18:09 analytophile