Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1192

FastDateFormat does not support the week-year component (uppercase 'Y')

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.4
    • 3.5
    • lang.time.*

    Description

      The Java SimpleDateFormat supports two year-components, 'y' for normal year and 'Y' for 'Week year', see http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

      However when we try to use FastDateFormat to parse a format which uses the week-year, it fails with an exception

      java.lang.IllegalArgumentException: Illegal pattern component: YYYY
      	at org.apache.commons.lang3.time.FastDatePrinter.parsePattern(FastDatePrinter.java:282)
      	at org.apache.commons.lang3.time.FastDatePrinter.init(FastDatePrinter.java:149)
      	at org.apache.commons.lang3.time.FastDatePrinter.<init>(FastDatePrinter.java:142)
      	at org.apache.commons.lang3.time.FastDateFormat.<init>(FastDateFormat.java:384)
      	at org.apache.commons.lang3.time.FastDateFormat.<init>(FastDateFormat.java:369)
      	at org.apache.commons.lang3.time.FastDateFormat$1.createInstance(FastDateFormat.java:91)
      	at org.apache.commons.lang3.time.FastDateFormat$1.createInstance(FastDateFormat.java:88)
      	at org.apache.commons.lang3.time.FormatCache.getInstance(FormatCache.java:82)
      	at org.apache.commons.lang3.time.FastDateFormat.getInstance(FastDateFormat.java:119)
      

      Simple unit test to reproduce this:

          @Test
          public void testCommonsLang() {
          	Date date = new Date();
      
          	Format dateFormat = new SimpleDateFormat("YYYY");
      		assertNotNull(dateFormat.format(date));
      
              dateFormat = FastDateFormat.getInstance("YYYY");
      		assertNotNull(dateFormat.format(date));
          }
      

      Attachments

        Issue Links

          Activity

            People

              chonton Charles Honton
              dominik.stadler@gmx.at Dominik Stadler
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: