You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Charles Honton (JIRA)" <ji...@apache.org> on 2015/07/08 06:17:04 UTC

[jira] [Resolved] (LANG-1152) FastDateFormat seems to behave differently with very large dates than simple date format

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

Charles Honton resolved LANG-1152.
----------------------------------
    Resolution: Fixed

> 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
>
> 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)