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

DayOfWeek interconversion with Calendar.DAY_OF_WEEK

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The issue is that DayOfWeek is not taking in consideration the implementation already existing for many years in the "java.util.Calendar" class
       
           * SUNDAY = 1
           * MONDAY = 2
           * TUESDAY = 3
           * WEDNESDAY= 4
           * THURSDAY = 5
           * FRIDAY = 6
           * SATURDAY = 7

      Where as DayOfWeek is considering different values:
          /**
           * The singleton instance for the day-of-week of Monday.
           * This has the numeric value of {@code 1}.
           */
          MONDAY,
          /**
           * The singleton instance for the day-of-week of Tuesday.
           * This has the numeric value of {@code 2}.
           */
          TUESDAY,
          /**
           * The singleton instance for the day-of-week of Wednesday.
           * This has the numeric value of {@code 3}.
           */
          WEDNESDAY,
          /**
           * The singleton instance for the day-of-week of Thursday.
           * This has the numeric value of {@code 4}.
           */
          THURSDAY,
          /**
           * The singleton instance for the day-of-week of Friday.
           * This has the numeric value of {@code 5}.
           */
          FRIDAY,
          /**
           * The singleton instance for the day-of-week of Saturday.
           * This has the numeric value of {@code 6}.
           */
          SATURDAY,
          /**
           * The singleton instance for the day-of-week of Sunday.
           * This has the numeric value of {@code 7}.
           */
          SUNDAY;

      therefore this makes its use inconsistent.

      Please Fix it ASAP!

      Many thanks :)

      Code:
      package com.company;

      import java.text.SimpleDateFormat;
      import java.time.DayOfWeek;
      import java.util.Calendar;
      import java.util.Date;
      import java.util.GregorianCalendar;
      import java.util.TimeZone;

      public class Main {

          public static void main(String[] args) {


      // write your code here
              Calendar myCalendar = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"));
              myCalendar.setTime(new Date());
              int dayOfWeek = myCalendar.get(Calendar.DAY_OF_WEEK);
              System.out.println("dayOfWeek \t: " + DayOfWeek.of(dayOfWeek).name() );
          }
      }

      Output:
      dayOfWeek : SATURDAY

      REGRESSION. Last worked in version 8u121


      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: