You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Emmanuel Lecharny (JIRA)" <ji...@apache.org> on 2015/07/01 17:35:05 UTC

[jira] [Comment Edited] (DIRAPI-241) new GeneralizedTime(String) fails for fraction close to one

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

Emmanuel Lecharny edited comment on DIRAPI-241 at 7/1/15 3:34 PM:
------------------------------------------------------------------

Even simpler :

{code}
    private void parseFractionOfSecond() throws ParseException
    {
        parseFractionDelmiter( 14 );
        String fraction = getFraction( 14 + 1 );
        upFractionLength = fraction.length();
        int milliseconds =  Integer.parseInt( fraction );

        switch ( upFractionLength )
        {
            case 1:
                milliseconds *= 10;
                
            case 2:
                milliseconds *= 10;
                
            case 3 :
                break;
                
            case 4 :
                milliseconds /= 10;
                break;
                
        }

        calendar.set( Calendar.MILLISECOND, milliseconds );
    }
{code}

No more Double, precision is 1ms with a potential delta of 0.5ms in the past. Note that the previous method precision was also 1ms, not 0.5ms : the difference is that everything between nnn5 and nn(n+1)4 was rounded to nn(n+1).


was (Author: elecharny):
Even simpler :

{code}
    private void parseFractionOfSecond() throws ParseException
    {
        parseFractionDelmiter( 14 );
        String fraction = getFraction( 14 + 1 );
        upFractionLength = fraction.length();

        int milliseconds =  Integer.parseInt( fraction ) / 10;

        calendar.set( Calendar.MILLISECOND, milliseconds );
    }
{code}

No more Double, precision is 1ms with a potential delta of 0.5ms in the past. Note that the previous method precision was also 1ms, not 0.5ms : the difference is that everything between nnn5 and nn(n+1)4 was rounded to nn(n+1).

> new GeneralizedTime(String) fails for fraction close to one
> -----------------------------------------------------------
>
>                 Key: DIRAPI-241
>                 URL: https://issues.apache.org/jira/browse/DIRAPI-241
>             Project: Directory Client API
>          Issue Type: Bug
>    Affects Versions: 1.0.0-M30
>            Reporter: Max Fichtelmann
>            Priority: Minor
>
> When parsing a time with a resolution of nanos (like generated by the openldap ppolicy overlay) it results in a Time that fails to be parsed by org.apache.directory.api.util.GeneralizedTime.GeneralizedTime(String)
> Test:
> {code:title=Test.java|borderStyle=solid}
>     static DateFormat FORMAT = new SimpleDateFormat( "dd/MM/yyyy HH:mm:ss.SSSS z" );
>     
>     @Test
>     public void fractionCloseToOne() throws ParseException
>     {
>         GeneralizedTime close = new GeneralizedTime( "20000101000000.9994Z" );
>         
>         assertThat( close.getDate(), is( equalTo( FORMAT.parse( "01/01/2000 00:00:00.999 GMT" ) ) ) );
>         
>         GeneralizedTime closer = new GeneralizedTime( "20000101000000.9995Z" );
>         
>         assertThat( closer.getDate(), is( equalTo( FORMAT.parse( "01/01/2000 00:00:01 GMT" ) ) ) );
>     }
> {code}



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