Skip to content

Conversation

BrianMitchL
Copy link
Contributor

This is based off of the logic in d3/d3#2151 and would close #8.

The logic for parsing is much more complicated than the other week formats (%W and %U), so I wasn't quite sure how to fit it in. Any new commits or suggestions of refactoring/rewriting are welcome 😄

@mbostock
Copy link
Member

mbostock commented Oct 7, 2017

An unrelated bug I noticed here: week number parsing should consume two characters at most. So in parseWeekNumberMonday, parseWeekNumberSunday, parseWeekNumberISO, instead of:

var n = numberRe.exec(string.slice(i));

It should say:

var n = numberRe.exec(string.slice(i, i + 2));

src/locale.js Outdated
d.m = 0;
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
if ("W" in d || "U" in d || "V" in d) {
if ("V" in d) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d split these if-else blocks:

if ("V" in d) {
  
} else if ("W" in d || "U" in d) {
  
}

@mbostock
Copy link
Member

mbostock commented Oct 7, 2017

Nicely done. Thank you for this pull request!

@BrianMitchL
Copy link
Contributor Author

That should do it.

@mbostock mbostock merged commit a3c36a0 into d3:master Oct 9, 2017
@mbostock
Copy link
Member

mbostock commented Oct 9, 2017

Thanks! Merged with a few tweaks.

@BrianMitchL BrianMitchL deleted the ISO-week-number branch October 3, 2018 02:37
@davinov davinov mentioned this pull request Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

ISO week number (%V)
2 participants