You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Padovan Luca (Commented) (JIRA)" <de...@myfaces.apache.org> on 2012/01/09 17:14:39 UTC

[jira] [Commented] (TOMAHAWK-1608) inputDate does not accept some dates when Daylight saving time

    [ https://issues.apache.org/jira/browse/TOMAHAWK-1608?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13182595#comment-13182595 ] 

Padovan Luca commented on TOMAHAWK-1608:
----------------------------------------

A better solution is invoke tempCalendar.clear() before set day, month and year
                
> inputDate does not accept some dates when Daylight saving time
> --------------------------------------------------------------
>
>                 Key: TOMAHAWK-1608
>                 URL: https://issues.apache.org/jira/browse/TOMAHAWK-1608
>             Project: MyFaces Tomahawk
>          Issue Type: Bug
>          Components: Date
>         Environment: Linux
>            Reporter: Padovan Luca
>
> 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

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira