directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DIRAPI-241) new GeneralizedTime(String) fails for fraction close to one
Date Wed, 01 Jul 2015 12:45:04 GMT

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

Emmanuel Lecharny commented on DIRAPI-241:
------------------------------------------

Woot, good catch !!!

At some point, when parsing the date, we parse the fraction of seconds with this method :

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

        double fract = Double.parseDouble( "0." + fraction ); <<<<-----------
Problem !!!
        int millisecond = ( int ) Math.round( fract * 1000 );

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

The rational for the round is that the Calendar only support milliseconds precision, while
the generalizedTime gowd down to a tenth of a millisecond. 9995 get rounded to 1000, which
is out of the possible values ([0..999]).

This is a bit of a problem as we have to cut the corner a bit (loosing some precision), and
more critical, if we have to round 999x to 1000 (when x >= 5), then we have to propagate
the extra time to seconds, and then minutes if we were at 59s, then to hours, etc.

In any case, it has to be fixed. 

(FTR, the issue is present since the very beginning, 7 years ago...)

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

Mime
View raw message