[ 
https://issues.apache.org/jira/browse/LANG-1029?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Charles Honton resolved LANG-1029.
----------------------------------

    Resolution: Won't Fix
      Assignee: Charles Honton

The timezone is an invariant of a FastDateFormat.  If changing the global 
timezone affected the behavior of an instance, the instance would have 
concurrency concerns.

If you want the current global timezone to be used on each invocation, use one 
of the FastDateFormat.getTimeInstance() factory methods which does not take a 
timezone parameter.  If the timezone has not been changed, you'll get a cached 
FastDateFormat instance; If the timezone has been changed, you'll get a new 
FastDateFormat that reflects the current global timezone. 

> FastDateFormat static instance format differently compared to new instance 
> when changing timezone
> -------------------------------------------------------------------------------------------------
>
>                 Key: LANG-1029
>                 URL: https://issues.apache.org/jira/browse/LANG-1029
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.3.2
>            Reporter: Sven Diedrichsen
>            Assignee: Charles Honton
>             Fix For: Patch Needed
>
>
> Static FastDateFormat instances don't recognize default TimeZone changes and 
> thus don't behave equal to newly created instances of FastDateFormat or 
> SimpleDateFormat.
> I can imagine people using FastDateFormat like this for performance 
> optimization reasons.
> {code:title=Test for difference}
>     private static final String DATE_TIME_PATTERN = "dd.MM.yyyy HH:mm:ss";
>     private static final FastDateFormat FDF = 
> FastDateFormat.getInstance(DATE_TIME_PATTERN);
>     public static void main(String[] args) {
>         TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT");
>         Calendar date = Calendar.getInstance();
>         date.setTimeZone(gmtTimeZone);
>         date.set(2014, Calendar.JANUARY, 1, 0, 0 ,0);
>         TimeZone backupTimeZone = TimeZone.getDefault();
>         TimeZone.setDefault(gmtTimeZone);
>         System.out.println("FastDateFormat static:\t\t"+ 
> FDF.format(date.getTime()));
>         System.out.println("FastDateFormat instance:\t" + 
> FastDateFormat.getInstance(DATE_TIME_PATTERN).format(date.getTime()));
>         System.out.println("SimpleDateFormat instance:\t" + new 
> SimpleDateFormat(DATE_TIME_PATTERN).format(date.getTime()));
>         TimeZone.setDefault(backupTimeZone);
>     }
> {code}
> {panel:title=Output}
> FastDateFormat static:                01.01.2014 01:00:00
> FastDateFormat instance:      01.01.2014 00:00:00
> SimpleDateFormat instance:    01.01.2014 00:00:00
> {panel}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to