JDK-4977067 : SimpleDateFormat should support DAY_OF_WEEK as digit as well
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.4.2
  • Priority: P5
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2004-01-12
  • Updated: 2018-08-16
  • Resolved: 2018-08-16
Related Reports
Relates :  
Description

Name: jl125535			Date: 01/12/2004


A DESCRIPTION OF THE REQUEST :
It would be usefull if SimpleDateFormat could print
(DAY_OF_WEEK-firstDayOfWeek+1) as a digit, since now
DAY_OF_WEEK can only be printed as a locale specific string.
This is an issue specifically in the case where I wish to
print ISO 8601 week specified dates (see
ftp://ftp.qsl.net/pub/g1smd/8601v03.pdf)

   Name:           Date pattern String:    Value:
   Calendar date:  "yyyy-MM-dd"            2001-05-02
   Ordinal date:   "yyyy-DDD"              2001-122
   Week spec date: "yyyy-'W'ww-??"         2001-W18-3

SimpleDateFormat has no pattern letter for this value, so
can not display, or parse week specified dates. Once
implemented, also consider adding factory methods to DateFormat:

   DateFormat.getISODateInstance()
   DateFormat.getISOOrdinalInstance()
   DateFormat.getISOWeekInstance()

Currently the pattern letter 'E' is implemented to be
DAY_OF_WEEK (as a String), and I think 'e' would be an
excellent candidate for DAY_OF_WEEK as a digit.  Like
WEEK_IN_YEAR, which relies upon
'Calendar.getMinimalDaysInFirstWeek()' the DAY_OF_WEEK as a
digit would rely upon 'Calendar.getFirstDayOfWeek()', with
firstDayOfWeek being '1'.


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER WORKAROUND :
1) to print:
Calendar calendar...
Date date....

SimpleDateFormat weekF = new SimpleDateFormat("yyyy-'W'ww-");
weekF.setCalendar(calendar);

calendar.setTime(date);
int dayOfWeek = ((calendar.get(Calendar.DAY_OF_WEEK) -
                  calendar.getFirstDayOfWeek() +7) %7) +1;
System.out.println(weekF.format(date)+dayOfWeek);


2) to parse:
I haven't had to but it will involve your own
StringTokenizer, calendar.get(Calendar.DAY_OF_WEEK),
calendar.getFirstDayOfWeek(), and some arithmetic.
(Incident Review ID: 180264) 
======================================================================

Comments
Recommended to use java.time APIs to get this behaviour, 'e' and 'ee' patterns in java.time.format.DateTimeFormatter provide numeric representation of the day-of-week.
16-08-2018

EVALUATION The DAY_OF_WEEK part will be addressed in 4267450. The requested factory methods may be added in a future release.
27-08-2010

EVALUATION The requested feature should be supported. ###@###.### 2004-01-13
13-01-2004