commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pas Filip (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1152) FastDateFormat seems to behave differently with very large dates than simple date format
Date Tue, 07 Jul 2015 15:13:05 GMT

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

Pas Filip commented on LANG-1152:
---------------------------------

I only tested the behavior on version 3.4 but I assume it's present in earler and later incarnations
too.

> 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
>            Priority: Minor
>
> Inconsistent behaviour compared to SimpleDateFormat.
> StringIndexOutOfBoundsException using one format and no exception when using another
format. (both legal).
> 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