New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microseconds (%f) #24
Comments
Those aren’t milliseconds; they are |
The %L does not like them any better |
There is no directive for parsing nanoseconds. There is only %L, which is for milliseconds. |
That is actually the core of my problem ;-) |
I found that a little workaround works, since I'm actually not using the fine details of nanoseconds, and it seems not to screw up the Date() creation. Using double %L in the template actually works.
But some might need the precision |
I would strongly not recommend that approach because it means that the last three digits of the nanoseconds field are interpreted as the milliseconds, rather than the first three digits. var parseTime = d3.utcParse("%Y-%m-%dT%H:%M:%S.%L%LZ");
parseTime("2016-10-06T20:32:56.523411Z").getUTCMilliseconds(); // 411, not 523 If you know the format is strictly var parseMilliseconds = d3.utcParse("%Y-%m-%dT%H:%M:%S.%LZ"),
stripNanoseconds = function(s) { return s.slice(0, -4) + "Z"; },
parseTime = function(s) { return parseMilliseconds(stripNanoseconds(s)); };
parseTime("2016-10-06T20:32:56.523411Z"); // Thu, 06 Oct 2016 20:32:56 GMT |
I realize that, but for now it works for me since I'm only using minutes as the finest grinder and just working on preliminary stage. As a matter of fact I'm testing the c3 library that of course relies on d3 and d3-time-format, but it does not give me any handle on the data itself and I was looking for a solution that could create simple graph with few lines of code. Of course I could fetch the json and create suitible dataset but that would take me astray from this mission of simplifying the making of graphs :-) |
I see—so you can specify the format but not an arbitrary function for parsing. A |
I actually did that previously, parse the data set, but it took some effort on a full set of data, 3 X60X24, or 4.320 entries and made a simple graph too slow. |
The cost of a single additional string.slice to strip the extra digits does not significantly increase the cost of date parsing (which already calls string.slice many times). |
It appears that this was committed but not merged? Is there a reason for this? I can really use this feature... |
var d3 = require("d3-time-format")
var parser = d3.timeParse("%Y-%m-%d %H:%M:%S.%f")
var date1 = parser("2017-09-29 19:20:38.888377")
var date2 = parser("2017-09-29 19:20:38.888376")
console.log(date1 > date2, date1 < date2) the result is
is there any way to compare the two date obj? |
@liugangnhm JavaScript Date objects only have millisecond resolution. |
@mbostock all right, I was looking for a javascript module that can parse time string with millisecond and this is the only one i hava found. but it seems that it could only parse . |
Hi
I'm having a problem parsing UTC timestamps with 6 digits.
2016-10-06T20:32:56.523411Z
It works just fine with three digits.
I'm working with realtime data so it could be messy and heavy workaround to shorten this before parsing. And changes at the source could be hard to get trough.
The text was updated successfully, but these errors were encountered: