-
Notifications
You must be signed in to change notification settings - Fork 99
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
Format %Z as ±HH:MM instead of ±HHMM? #35
Comments
This is the expected behavior when formatting the %Z directive. (Parsing %Z is more flexible: we support ±HH, ±HH:MM, ±HHMM and the literal Z.) But, it might be possible to extend the %Z directive to include a modifier, similar to how %-d disables the default zero padding. Not entirely sure how that would work since the padding modifiers are applied generically to all directives, and this wouldn’t be a padding modifier per se (unless we want to arbitrarily overload the meaning of the padding modifier in the context of formatting the time zone offset, which is probably inadvisable). Or, another possibility would be to introduce another directive, like %z, for ±HH:MM. Or, we could just change the behavior of %Z. I think that would probably also be inadvisable for backwards-compatibility reasons, though perhaps it could be done with a major version bump. |
Thanks for taking the time to look into this somewhat obscure issue! :-) I had indeed noticed PR #4 which made the date parsing looser for timezone formatting You have a good point that changing the behavior of %Z could be inadvisable for backward compatibility reasons. Using the padding modifiers ( There's also the fact that there isn't currently a way to choose whether I'd be inclined to look at some type of syntax for the format string like I'm not sure how difficult it would be to implement parameterized variants of I suppose that if people see some value in it then I could try to find the time to make a PR. |
Hi everyone, I have a function like this: But when i call: When i change the format to Can you please say me why %Z is not parsing the +01:00 in my example? |
@Sionicmon You are using an old version of D3. The relaxed %Z parser was added in D3 4.0 / d3-time-format 1.0. Here is an example: |
@mbostock Thanks for your help! |
I believe this is covered by #6. |
I have an application that's parsing date strings with a format that includes
%Z
like in the example below:The
formattedDateString
is equal to2017-09-15T06:00:00+0000
as expected given the return value of theformatZone
function (https://github.com/d3/d3-time-format/blob/master/src/locale.js#L523)The trouble is that in the above code
newDateObject
has the expected Date value in Chrome/Firefox/Edge, but is a Date which is flagged as aninvalid date
in Safari or IE11.I need to pass date strings to a library that then converts them to Date objects, and I'm using
utcHour
fromd3-time
to generate some of the date strings. Given those constraints I was able to work around this problem using the following code instead of just callingdateFormatter(date)
directly:TLDR; In Safari and IE11 the Date constructor requires the timezones to be formatted with a
:
(colon) to be able to parse from date strings.I get that this is probably a minor concern for d3, since
utcParse
exists (and local variants as well), but I was curious to know if there was a strong reason for not changing the default formatting to format time zones as+00:00
instead of+0000
. This would allow ISO 8601 date strings to be generated withd3-time-format
in a way that could be natively parsed in all browsers.The text was updated successfully, but these errors were encountered: