Okay so this one is stumping me. I have the following code which attempts to create this string:
OUTPUT: 52. 2012 (24 Dec to 30 Dec)
Which is the start and end of the 52nd week of the year 2012, with Monday being the first day of the week.
private Date getDateObject() {
Calendar cld = Calendar.getInstance();
cld.set(Calendar.YEAR, year);
cld.set(Calendar.WEEK_OF_YEAR, week);
cld.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
return cld.getTime();
}
private Date getEndDateObject() {
Calendar cld = Calendar.getInstance();
if (week < 52) {
cld.set(Calendar.YEAR, year);
cld.set(Calendar.WEEK_OF_YEAR, week + 1);
} else {
cld.set(Calendar.YEAR, year + 1);
cld.set(Calendar.WEEK_OF_YEAR, 1);
}
cld.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
return cld.getTime();
}
public String getDateRangeString() {
String pattern = "d MMM";
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
Date startDate = getDateObject();
Date endDate = getEndDateObject();
String startDateFormatted = formatter.format(startDate);
String endDateFormatted = formatter.format(endDate);
String dateString = "" + this.week + ". " + this.year + " (" + startDateFormatted + " to " + endDateFormatted + ")";
return dateString;
}
The function getDateRangeString when used on the object with YEAR = 2012 and WEEK = 52 gives the following output on the following devices:
- Nexus S - 4.1
- Emulator 4.1
- Emulator 4.2
OUTPUT: 52. 2012 (24 Dec to 30 Dec)
Which is correct!
But on the Nexus 7 running 4.2.1 I get:
OUTPUT: 52. 2012 (24 Dec to 6 Jan)
WTF!!?!?
All devices are set to Australian EST +10 and have correct time / date right now. I don't think this has anything to do with the missing December month in 4.2 which should be fixed in 4.2.1 anyway.
When I debug it, the calendar says it has all the correct values. Then out comes 6th of Jan?
I mean its a weird one coz the 31st of December is like a 53rd week or something? I dunno, I just don't get why this device is in any way different.