Bug in PrettyTime.calculatePreciseDuration() for past events?

Splash Forums PrettyTime Users Bug in PrettyTime.calculatePreciseDuration() for past events?

This topic contains 1 reply, has 2 voices, and was last updated by  Lincoln Baxter III 7 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #17735

    Anonymous

    Hi, I am running PrettyTime-1.0.6 for Java and have run into a problem with the method cited in the title. I am executing code similar to the following:

    PrettyTime formatter = new PrettyTime();
    formatter.setUnits(new Second(Locale.getDefault()), new Minute(Locale.getDefault()), new Hour(Locale.getDefault()), new Day(Locale.getDefault()));

    Date futureDate = new Date(new Date().getTime() + 1991701000L);
    List<Duration> durations = formatter.calculatePreciseDuration(futureDate);
    for(Duration curDuration:durations){
    //do some string manipulation...
    }
    //print out result

    The result of this code is: “23 days, 1 hour, 15 minutes, 1 second from now”, which is precisely what I want.

    However, if I use a past date, I lose all of the precision:

    //same as above
    Date pastDate = new Date(new Date().getTime() - 1991701000L);
    List<Duration> durations = formatter.calculatePreciseDuration(pastDate);
    //same as above

    The result of this code is: “23 days ago”.

    I was expecting “23 days, 1 hour, 15 minutes, 1 second ago”, and I’m not sure why I’m not getting it. Is this a bug? A result of my ignorance? Please help.

    Regards,

    Frank

    #19886

    Sounds like a bug. Could you file an issue?

    http://code.google.com/p/prettytime/issues/entry

    Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.