FULL PRODUCT VERSION :
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 64 Bit
A DESCRIPTION OF THE PROBLEM :
java.time.ZonedDateTime API get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) is returning incorrect Week of Year for the Year 2049 (1st to 3rd Jan of 2049).
Check the sample output
=====================
Date provided -> 2049-01-02T03:48:00Z
Using ZonedDateTime API:: Year 2049 weekOfYear 53
Using Calendar API:: Year 2049 weekOfYear 1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code given in "Source code for an executable test case:" field.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
2nd Jan of 2019 should be First week of 2049, instead it is showing as 53rd week of 2049
ACTUAL -
2nd Jan of 2019 should be First week of 2049, instead it is showing as 53rd week of 2049
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Date;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.IsoFields;
import java.util.Calendar;
/**
* Created by kanchan on 08-01-2017.
*/
public class ZonedDateTimeTest {
public static void main(String[] args) throws InterruptedException {
String instantStr = "2049-01-02T03:48:00Z";
System.out.println("Date provided -> " + instantStr);
ZonedDateTime utcTimestamp = parseToInstant(instantStr).atZone(ZoneOffset.UTC);
int year = utcTimestamp.getYear();
int weekOfYear = utcTimestamp.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
System.out.println("Using ZonedDateTime API:: Year " + year + " weekOfYear " + weekOfYear);
Date d1 = Date.from(parseToInstant(instantStr));
Calendar cl = Calendar.getInstance();
cl.setTime(d1);
int year1 = cl.get(Calendar.YEAR);
int weekOfYear1 = cl.get(Calendar.WEEK_OF_YEAR);
System.out.println("Using Calendar API:: Year " + year1 + " weekOfYear " + weekOfYear1);
}
public static Instant parseToInstant(final String ISODate) {
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(ISODate, Instant::from);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
We are using Calendar API, but did not expect new API like ZonedDateTime will blow like this.
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 64 Bit
A DESCRIPTION OF THE PROBLEM :
java.time.ZonedDateTime API get(IsoFields.WEEK_OF_WEEK_BASED_YEAR) is returning incorrect Week of Year for the Year 2049 (1st to 3rd Jan of 2049).
Check the sample output
=====================
Date provided -> 2049-01-02T03:48:00Z
Using ZonedDateTime API:: Year 2049 weekOfYear 53
Using Calendar API:: Year 2049 weekOfYear 1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code given in "Source code for an executable test case:" field.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
2nd Jan of 2019 should be First week of 2049, instead it is showing as 53rd week of 2049
ACTUAL -
2nd Jan of 2019 should be First week of 2049, instead it is showing as 53rd week of 2049
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Date;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.IsoFields;
import java.util.Calendar;
/**
* Created by kanchan on 08-01-2017.
*/
public class ZonedDateTimeTest {
public static void main(String[] args) throws InterruptedException {
String instantStr = "2049-01-02T03:48:00Z";
System.out.println("Date provided -> " + instantStr);
ZonedDateTime utcTimestamp = parseToInstant(instantStr).atZone(ZoneOffset.UTC);
int year = utcTimestamp.getYear();
int weekOfYear = utcTimestamp.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
System.out.println("Using ZonedDateTime API:: Year " + year + " weekOfYear " + weekOfYear);
Date d1 = Date.from(parseToInstant(instantStr));
Calendar cl = Calendar.getInstance();
cl.setTime(d1);
int year1 = cl.get(Calendar.YEAR);
int weekOfYear1 = cl.get(Calendar.WEEK_OF_YEAR);
System.out.println("Using Calendar API:: Year " + year1 + " weekOfYear " + weekOfYear1);
}
public static Instant parseToInstant(final String ISODate) {
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(ISODate, Instant::from);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
We are using Calendar API, but did not expect new API like ZonedDateTime will blow like this.