ocpsoft / prettytime

Social Style Date and Time Formatting for Java
http://ocpsoft.org/prettytime/
Apache License 2.0
1.29k stars 253 forks source link

36-48 hours resolved as `2 days ago` instead of `1 day ago` #219

Closed linama closed 1 year ago

linama commented 3 years ago

Hey so during our testing we noticed that the time that's 36 - 48 hours before the current time, the time string will return '2 days ago' instead of '1 day ago'. We are wondering if it's supposed to be '1 day ago' for this case?? Since 2 days ago should be anything that's earlier than 48hours to 72hours. please let me know. thanks!

Anass-ABEA commented 3 years ago

I believe it has to do with the tolerance used. For some reason, the roundingTolerance is set to 50 or 50%

For example, let's say the time from a date X till now is in days (2 days in reality). If the difference in hours, modulo 24 is less than 50% of 24 (for example 26 or 30 hours) the result will be in fact 2 days but if the time is greater than 50% it will increment the returned value by 1. So the result will be 3 days.

The same goes for months, but instead of modulo 24 it's modulo 30.

@linama sadly you can't change the tolerance but if you want to use the real value 100% accurate you can clone the project and change the private int roundingTolerance = 50; to private int roundingTolerance = 100; in SimpleTimeFormat.java

lincolnthree commented 3 years ago

You can change the tolerance by overriding / providing your own TimeFormat and configuring the PrettyTime instance to use it.