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

ASF GitHub Bot commented on WW-4799:
------------------------------------

Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts/pull/141#discussion_r123429169
  
    --- Diff: 
core/src/main/java/com/opensymphony/xwork2/conversion/impl/DateConverter.java 
---
    @@ -48,7 +51,28 @@ public Object convertValue(Map<String, Object> context, 
Object target, Member me
                     }
                 } else if (java.util.Date.class == toType) {
                     Date check;
    -                DateFormat[] dfs = getDateFormats(locale);
    +
    +
    +                // Add the user provided date format if any
    +                final TextProvider tp = findProviderInStack((ValueStack) 
context.get(ActionContext.VALUE_STACK));
    +                SimpleDateFormat globalDateFormat = null;
    +
    +                if (tp != null) {
    +                    String globalFormat = 
tp.getText(org.apache.struts2.components.Date.DATETAG_PROPERTY);
    +
    +                    // if tp.getText can not find the property then the
    +                    // returned string is the same as input =
    +                    // DATETAG_PROPERTY
    +                    if (globalFormat != null
    +                        && 
!org.apache.struts2.components.Date.DATETAG_PROPERTY.equals(globalFormat)) {
    +                        globalDateFormat = new 
SimpleDateFormat(globalFormat, locale);
    +                    }
    +                }
    --- End diff --
    
    Could you move this whole section into `getDateFormats` to avoid passing 
the `globalDateFormat` as a parameter? Also it would be good to extract this 
logic into a protected method to allow override, so the finally it should look 
like this:
    
    ```java
         DateFormat[] dfs = getDateFormats(globalDateFormat, locale);
    
    ...
    
    private DateFormat[] getDateFormats(Locale locale) {
        ...
        DateFormat globalDateFormat = getGlobalDateFormat();
        ...
    }
    
    protected getGlobalDateFormat() {
         // your code here
    }
    ```


> make DateConverter configurable
> -------------------------------
>
>                 Key: WW-4799
>                 URL: https://issues.apache.org/jira/browse/WW-4799
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Core
>            Reporter: Christoph Nenning
>            Priority: Minor
>             Fix For: 2.6
>
>
> Currently DateConverter has some logic to test which DateFormat is able to 
> parse given Date and use that one.
> The order in which DateFormats are tested is:
> * Locale specific DateTime LONG
> * Locale specific DateTime MEDIUM
> * Locale specific DateTime SHORT
> * rfc3339 ("yyyy-MM-dd'T'HH:mm:ss")
> * Locale specific Date SHORT
> * Locale specific Date MEDIUM
> * Locale specific Date LONG
> * rfc3339dateOnly ("yyyy-MM-dd")
> Would be great if apps could configure this. E.g. by:
> * defining an own list
> * defining order of objects in current list
> * defining just one DateFormat to be used
> * defining just which of Locale specific DateFormats to use (SHORT vs LONG)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to