lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Smiley (JIRA)" <>
Subject [jira] Commented: (LUCENE-1653) Change DateTools to not create a Calendar in every call to dateToString or timeToString
Date Tue, 30 Jun 2009 02:59:47 GMT


David Smiley commented on LUCENE-1653:

I'm looking through DateTools now and can't help but want to clean it up some.  One thing
I see that is odd is the use of a Calendar in timeToString(long,resolution).  The first two
lines look like this right now:
calInstance.setTimeInMillis(round(time, resolution));
Date date = calInstance.getTime();

Instead, it can simply be:
Date date = new Date(round(time, resolution));

Secondly... I think a good deal of logic can be cleaned up in the other methods instead of
a bunch of if-else statements that is a bad code smell.  Most of the logic of 3 of those methods
could be put into Resolution and be made tighter.

> Change DateTools to not create a Calendar in every call to dateToString or timeToString
> ---------------------------------------------------------------------------------------
>                 Key: LUCENE-1653
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Other
>            Reporter: Shai Erera
>            Assignee: Mark Miller
>            Priority: Minor
>             Fix For: 2.9
>         Attachments: LUCENE-1653.patch, LUCENE-1653.patch
> DateTools creates a Calendar instance on every call to dateToString and timeToString.
> # timeToString calls Calendar.getInstance on every call.
> # dateToString calls timeToString(date.getTime()), which then instantiates a new Date().
I think we should change the order of the calls, or not have each call the other.
> # round(), which is called from timeToString (after creating a Calendar instance) creates
another (!) Calendar instance ...
> Seems that if we synchronize the methods and create the Calendar instance once (static),
it should solve it.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message