Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8190952

Calendar.add(Calendar.WEEK_OF_YEAR, 1) returning incorrect value

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      I want my Java program to add weeks in year to a given week, which is in "yyyyww" format.

      For example I have "201701" which indicates 1st week of the year 2017. I want to add 2 weeks to this value. So I use "add" method of java.util.Calendar class (more details mentioned in source code). I get 201703. Perfect till now.

      If I add 1 week to 201752 then I get 201801. Perfect.

      But when I add 1 week to 201852 then I get 201801. Oops!


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      201901
      ACTUAL -
      201801

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      final String startWeek = "201852";

      SimpleDateFormat sdf = sdf = new SimpleDateFormat("yyyyww");

      Calendar calStart = Calendar.getInstance();

      calStart.setTime(sdf.parse(startWeek));

      calStart.add(Calendar.WEEK_OF_YEAR, 1);

      System.out.println(sdf.format(calStart.getTime()));

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                naoto Naoto Sato
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: