commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (LANG-1152) FastDateFormat seems to behave differently with very large dates than simple date format
Date Wed, 08 Jul 2015 09:33:05 GMT

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

Benedikt Ritter updated LANG-1152:
----------------------------------
    Fix Version/s: 3.5

> FastDateFormat seems to behave differently with very large dates than simple date format
> ----------------------------------------------------------------------------------------
>
>                 Key: LANG-1152
>                 URL: https://issues.apache.org/jira/browse/LANG-1152
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.x
>         Environment: ANY
>            Reporter: Pas Filip
>            Assignee: Charles Honton
>            Priority: Minor
>             Fix For: 3.5
>
>
> Inconsistent behaviour compared to SimpleDateFormat.
> StringIndexOutOfBoundsException using one format and no exception when using another
format. (both legal).
> Different results when using another format.
> Testcase:
> import org.apache.commons.lang3.time.FastDateFormat;
> import org.hamcrest.Matchers;
> import org.junit.Assert;
> import org.junit.Test;
> import java.text.SimpleDateFormat;
> import java.util.Date;
> public class FastDateFormatBug {
>     @Test
>     public void testFastFormatWitLongMaxValue(){
>         Date date = new Date(Long.MAX_VALUE);
>         String dateAsString = FastDateFormat.getInstance("yyyy-MM-dd").format(date);
>         Assert.assertThat(dateAsString, Matchers.equalTo("292278994-08-17"));
>     }
>     @Test
>     public void testWeirdResultWithMaxValue(){
>         Date date = new Date(Long.MAX_VALUE);
>         String dateAsString = FastDateFormat.getInstance("dd/MM/yyyy").format(date);
>         Assert.assertThat(dateAsString, Matchers.equalTo("292278994-08-17"));
>     }
>     @Test
>     public void testSimpleFormatWithLongMaxValueWithLenientOff(){
>         Date date = new Date(Long.MAX_VALUE);
>         SimpleDateFormat fft = new SimpleDateFormat("yyyy-MM-dd");
>         fft.setLenient(false);
>         String dateAsString = fft.format(date);
>         Assert.assertThat(dateAsString, Matchers.equalTo("292278994-08-17"));
>     }
>     @Test
>     public void testSimpleFormatWithLongMaxValueWithLenientOn(){
>         Date date = new Date(Long.MAX_VALUE);
>         SimpleDateFormat fft = new SimpleDateFormat("yyyy-MM-dd");
>         fft.setLenient(true);
>         String dateAsString = fft.format(date);
>         Assert.assertThat(dateAsString, Matchers.equalTo("292278994-08-17"));
>     }
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message