Last active
September 15, 2015 11:59
-
-
Save jonelf/c79bd3ed62d09d3f0c20 to your computer and use it in GitHub Desktop.
Week numbers are hard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Week numbers are hard. Here's a bug I found earlier today. | |
// If you want to construct a string like this | |
String yearWeekKey = year + week; | |
// then you can't use | |
String year = new SimpleDateFormat("yyyy").format(date); | |
String week = String.format("%02d", new LocalDate(date).getWeekOfWeekyear()); | |
// when date is 2016-01-01 because the key will be "201653" and that week does not exist. | |
// Instead you have to use .weekyear() because that correctly returns 2015 for 2016-01-01. | |
String year = new DateTime(ets).weekyear().getAsString(); | |
// Result "201553" | |
// PS. Joda-Time and ISO 8601 applies DS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment