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

(cal) Provide way to get "first Tuesday in month" from java.util.Calendar

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      java.util.Calendar lets you set the WEEK_OF_MONTH, and the DAY_OF_WEEK_IN_MONTH. Together with the DAY_OF_WEEK field this means you can uniquely specify a weekday.

      Unfortunately, a given Tuesday, say, is relative to either (a) the week of the month as determined by the getMinimalDaysInFirstWeek()/getFirstDayOfWeek() method pair, or (b) nothing really (that's what DAY_OF_WEEK_IN_MONTH is for).

      So there is no way to say "the first Tuesday in November" in one shot, which is the most common use case.

      JUSTIFICATION :
      This is the most common use case for calendaring applications ("takes place on the second Tuesday of the month", which of course is not DAY_OF_WEEK_IN_MONTH == 2 && DAY_OF_WEEK == TUESDAY, nor is it WEEK_OF_MONTH == 2 && DAY_OF_WEEK == TUESDAY).

      The edge cases illustrate this. The first Tuesday of November, 1996 is November 5, but java.util.Calendar will return October (!) 29 if you use any combination of DAY_OF_WEEK_IN_MONTH, WEEK_OF_MONTH, or DAY_OF_WEEK.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would like to see a field added to java.util.Calendar that picks out the first weekday specified that is also after DAY_OF_MONTH == 1.

            okutsu Masayoshi Okutsu
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: