MyFaces Tomahawk
  1. MyFaces Tomahawk
  2. TOMAHAWK-1608

inputDate does not accept some dates when Daylight saving time

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.12
    • Component/s: Date
    • Labels:
      None
    • Environment:
      Linux

      Description

      In Italy Daylight saving time started, in past, at midnight (now 2 AM). See http://www.inrim.it/res/tf/ora_legale_i.shtml
      The inputDate component set hours, minutes, seconds and milliseconds at zero but for example the 1979-05-27 00:00:00 didn't exist in Italy and then the component throws an exception.

      My solution, if can be useful, is edit the source code of class org.apache.myfaces.custom.date.AbstractHtmlInputDate using Calendar.clear(field) instead Calendar.set(field, 0)

      // old
      if( type.equals("date") )

      { //Reset hour, minute, second and milisecond to type date tempCalendar.set(Calendar.HOUR_OF_DAY, 0); tempCalendar.set(Calendar.MINUTE, 0); tempCalendar.set(Calendar.SECOND, 0); tempCalendar.set(Calendar.MILLISECOND, 0); return new java.sql.Date(tempCalendar.getTimeInMillis()); }

      // new
      if( type.equals("date") )

      { //Reset hour, minute, second and milisecond to type date tempCalendar.clear(Calendar.HOUR); tempCalendar.clear(Calendar.HOUR_OF_DAY); tempCalendar.clear(Calendar.AM_PM); tempCalendar.clear(Calendar.MINUTE); tempCalendar.clear(Calendar.SECOND); tempCalendar.clear(Calendar.MILLISECOND); return new java.sql.Date(tempCalendar.getTimeInMillis()); }

      this solution returns the date 1979-05-27 01:00:00 but didn't throws any Exception, i think that this is the correct behavior.

      A piece of code to test error with Italy localization is
      TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
      Calendar c = Calendar.getInstance();
      c.setLenient(Boolean.FALSE);
      c.set(Calendar.YEAR, 1979);
      c.set(Calendar.MONTH, 4); // May
      c.set(Calendar.DAY_OF_MONTH, 27);
      boolean error = true;
      if (error)

      { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); }

      else

      { c.clear(Calendar.HOUR); c.clear(Calendar.HOUR_OF_DAY); c.clear(Calendar.AM_PM); c.clear(Calendar.MINUTE); c.clear(Calendar.SECOND); c.clear(Calendar.MILLISECOND); }

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      System.out.println(sdf.format(c.getTime()));

      The dates with error in Italy are:
      1916 - 6 - 3
      1917 - 4 - 1
      1918 - 3 - 10
      1919 - 3 - 2
      1920 - 3 - 21
      1940 - 6 - 15
      1947 - 3 - 16
      1966 - 5 - 22
      1967 - 5 - 28
      1968 - 5 - 26
      1969 - 6 - 1
      1970 - 5 - 31
      1971 - 5 - 23
      1972 - 5 - 28
      1973 - 6 - 3
      1974 - 5 - 26
      1975 - 6 - 1
      1976 - 5 - 30
      1977 - 5 - 22
      1978 - 5 - 28
      1979 - 5 - 27

        Activity

        Hide
        Leonardo Uribe added a comment -

        I checked the code and Calendar javadocs, and the best way to do it is call first "set" and then "clear". I added a junit test for this one. Thanks to Padovan Luca for provide this patch.

        Show
        Leonardo Uribe added a comment - I checked the code and Calendar javadocs, and the best way to do it is call first "set" and then "clear". I added a junit test for this one. Thanks to Padovan Luca for provide this patch.

          People

          • Assignee:
            Leonardo Uribe
            Reporter:
            Padovan Luca
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development