You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Alf Støyle (JIRA)" <ji...@apache.org> on 2010/04/19 14:41:51 UTC

[jira] Created: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

DatePicker does not parse year with pattern dd.MM.yyyy correctly.
-----------------------------------------------------------------

                 Key: WICKET-2841
                 URL: https://issues.apache.org/jira/browse/WICKET-2841
             Project: Wicket
          Issue Type: Bug
          Components: wicket-datetime
            Reporter: Alf Støyle


We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).

For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.

I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?

Thanks
- Alf

diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
index 7f19c55..420f075 100644
--- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
+++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
@@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
        // optionally do some padding to match the pattern
        if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
        if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
-        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
+       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
        // replace pattern with real values
        return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
 }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Martin H. (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12861294#action_12861294 ] 

Martin H. edited comment on WICKET-2841 at 4/27/10 3:54 AM:
------------------------------------------------------------

Oh, i forgot to mention. There is a workaround to get a full year: Overriding the getDatePattern of the DatePicker class with a format with just one letter 'y' doesn't trigger the bug in the javascript. But it's of course not a clean way. e.g.
add(new DatePicker() {
			// Workaround for wicket bug WICKET-2841
			protected String getDatePattern() {
				return "dd.MM.y";
			}
}

      was (Author: textshell):
    Oh, i forgot to meanting. There is a workaround to get a full year: Overriding the getDatePattern of the DatePicker class with a format with just one letter 'y' doesn't trigger the bug in the javascript. But it's of course not a clean way. e.g.
add(new DatePicker() {
			// Workaround for wicket bug WICKET-2841
			protected String getDatePattern() {
				return "dd.MM.y";
			}
}
  
> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Martin H. (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12863733#action_12863733 ] 

Martin H. commented on WICKET-2841:
-----------------------------------

In my testing this seems to be fixed in wicket 1.4.8. Alf Støyle do you agree that this can be closed now?

> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Martin H. (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12861294#action_12861294 ] 

Martin H. commented on WICKET-2841:
-----------------------------------

Oh, i forgot to meanting. There is a workaround to get a full year: Overriding the getDatePattern of the DatePicker class with a format with just one letter 'y' doesn't trigger the bug in the javascript. But it's of course not a clean way. e.g.
add(new DatePicker() {
			// Workaround for wicket bug WICKET-2841
			protected String getDatePattern() {
				return "dd.MM.y";
			}
}

> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Martin H. (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12861293#action_12861293 ] 

Martin H. commented on WICKET-2841:
-----------------------------------

I can reproduce this bug. If i specify a format with just two digit year the java side seems to sanely interpret the 2 digit year. 
But the javascript part fails to respect 4 year date formats and just returns 2 digits which then gets misinterpreted as full year in the java part and the model ends up with dates < 100 year a.d. instead of in this or the last century.
so i think a better fix would be to explicitly check for both cases.

if(datePattern.match(/yyyy/)) {
   year=""+year;
   year = "0000".slice(0,4-year.length) + year;
} else if(datePattern.match(/yy/)) year = Wicket.DateTime.padDateFragment(year % 100); 

This should work for the common cases. (i.e. formated to 2 or 4 digits, year < 10000). But if required i should be able to write code that completly handles all valid cases. Also if need to fix this bug i can supply a real patch, but it shouldn't be much additional work to change this manually with help of the location information in the patch of the original reporter.

> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Alf Støyle (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12861704#action_12861704 ] 

Alf Støyle commented on WICKET-2841:
------------------------------------

The workaround works for us, so we have used that to avoid our local patched version of the jar.

I think you should definitely apply the fix you've suggested. If not it should be clear from the documentation of DatePicker and DateTextField how to apply the workaround.

Thanks for looking into this.

> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Peter Ertl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Ertl closed WICKET-2841.
------------------------------

    Resolution: Fixed

closed as requested

> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2841) DatePicker does not parse year with pattern dd.MM.yyyy correctly.

Posted by "Alf Støyle (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2841?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12863735#action_12863735 ] 

Alf Støyle commented on WICKET-2841:
------------------------------------

Yes, I agree. Close this issue.

By the way, sorry I didn't see WICKET-2767. I tried search for related issues, before I registered this one.

> DatePicker does not parse year with pattern dd.MM.yyyy correctly.
> -----------------------------------------------------------------
>
>                 Key: WICKET-2841
>                 URL: https://issues.apache.org/jira/browse/WICKET-2841
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-datetime
>            Reporter: Alf Støyle
>
> We use the date pattern dd.MM.yyyy, and when returning from the date picker (org.apache.wicket.extensions.yui.calendar.DatePicker) yields incorrect value in the date text field (org.apache.wicket.extensions.markup.html.form.DateTextField).
> For instance picking the date 19.04.2010 in the date picker, yields 19.04.10, which again becomes the java.util.Date 19.04.0010. We have found the source of the problem, and created a fix for this, but hopefully you can fix this in a later release, so we do not have to maintain a local patched version of wicket-datetime.
> I have included the patch here. However this code seems very intentional, so applying this patch may be breaking something else!?
> Thanks
> - Alf
> diff --git a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> index 7f19c55..420f075 100644
> --- a/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> +++ b/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
> @@ -134,7 +134,7 @@ Wicket.DateTime.substituteDate = function(datePattern, date) {
>         // optionally do some padding to match the pattern
>         if(datePattern.match(/dd+/)) day = Wicket.DateTime.padDateFragment(day);
>         if(datePattern.match(/MM+/)) month = Wicket.DateTime.padDateFragment(month);
> -        if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year % 100);
> +       if(datePattern.match(/yy+/)) year = Wicket.DateTime.padDateFragment(year);
>         // replace pattern with real values
>         return datePattern.replace(/d+/, day).replace(/M+/, month).replace(/y+/, year);
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.