commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philip Hodges (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1432) FastDateFormat doesn't parse time string with timezone correctly
Date Fri, 15 Mar 2019 20:42:00 GMT

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

Philip Hodges commented on LANG-1432:
-------------------------------------

Precondition (implicit in submitter's example):
 * default timezone China (which has an ambiguous abbreviation CST)

Expected by submitter:
 * FastDateTime.parse interprets a CST date as China Standard Time (UTC+8)
like SimpleDateFormat.parse apparently does.

Found:
 * FastDateTime.parse interprets a CST date as Central Standard Time (UTC-6).

What might be best for an ambiguous timezone like CST:
 * choose the most likely interpretation if the parser's timezone is in the same region?
 * choose a consistent interpretation if the parser's timezone is in another region?
 * throw an exception because the parse is ambiguous?
 * make it depend on whether the parse is strict or lenient?
 * use whatever java.time does since Java 8 instead?

 

> FastDateFormat doesn't parse time string with timezone correctly
> ----------------------------------------------------------------
>
>                 Key: LANG-1432
>                 URL: https://issues.apache.org/jira/browse/LANG-1432
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.8.1
>         Environment: jdk 1.8
>            Reporter: Simon Xianyu
>            Priority: Major
>
> FastDateFormat doesn't parse the pattern correctly : 
> "EEE MMM dd HH:mm:ss zzz yyyy"
> The test code is as following:
>   
> {code:java}
> // code placeholder
> public class TestFastDateFormat {
>   public static void main(String[] args) throws ParseException {
>     Date d = new Date();
>     String dstr = d.toString();
>     System.out.println(dstr);
>     String pattern = "EEE MMM dd HH:mm:ss zzz yyyy";
>     FastDateFormat fdf = FastDateFormat.getInstance(pattern,
>         Locale.US);
>     Date d1 = fdf.parse(dstr);
>     System.out.println(d1);
>     // Use SimpleDateFormat to parse string
>     SimpleDateFormat sdf = new SimpleDateFormat(pattern);
>     Date d2 = sdf.parse(dstr);
>     System.out.println(d2);
>   }
> }
> {code}
> The test result example:
>  Tue Feb 12 16:07:53 CST 2019    /// this is origin result
>  Wed Feb 13 06:07:53 CST 2019   /// this is result of FastDateTime.parse()
>  Tue Feb 12 16:07:53 CST 2019    /// this is result of SimpleDateFormat.parse()
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message