Skip to content
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

number of digits in %L #40

Closed
braunmpifkf opened this issue Nov 24, 2017 · 2 comments
Closed

number of digits in %L #40

braunmpifkf opened this issue Nov 24, 2017 · 2 comments

Comments

@braunmpifkf
Copy link

A timestamp created by Python datetime.datetime.today().isoformat() outputs 2017-11-21T08:34:28.150206. When reading this in from file and parsing it with d3.utcParse("%Y-%m-%dT%H:%M:%S.%L"), I get an error since the fractional seconds part has six instead of three digits. Without knowing what the ISO standard really specifies there, it were nice if %L could either be more lenient and accept any number of consecutive digits, or the number of digits could be specified. This would save the effort of having to truncate/reformat the string before parsing it and would allow direct export/import of ISO datetime data.

@mbostock
Copy link
Member

mbostock commented Nov 24, 2017

You can use %f to parse microseconds, though note that JavaScript dates only have millisecond resolution so this loses information. This feature was added in d3-time-format 2.1.0 (d3 4.12.0).

@mbostock
Copy link
Member

Also, if you don’t mind relying on relatively recent browsers, you can use d3.isoParse to parse these strings instead (or simply use the Date constructor). You will need to add the trailing Z for UTC.

d3.isoParse("2017-11-21T08:34:28.150206Z") // Tue Nov 21 2017 03:34:28 GMT-0500 (EST)
new Date("2017-11-21T08:34:28.150206Z") // Tue Nov 21 2017 03:34:28 GMT-0500 (EST)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants