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

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

Pas Filip created LANG-1152:
-------------------------------

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