ocpsoft / prettytime

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

Ukrainian time is sometimes formatted with a negative sign #269

Closed moontoaster closed 2 months ago

moontoaster commented 3 months ago

When using PrettyTime.formatUnrounded with a date in the past and locale set to Ukrainian, the time will have a negative sign prepended to it, like so: -10 хвилин тому (-10 minutes ago).

This is due to Ukrainian locale using duration's quantity directly, which can be negative.

Polish locale, which has similar code structure to Ukrainian locale, solves this by getting the absolute value of duration's quantity in unrounded functions.

I wrote a tiny test that reproduces this bug. It's located at https://github.com/moontoastingenterprises/prettytime-bug-repro. When I ran it, the testFormatUnrounded test failed with the following:

[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.041 s <<< FAILURE! - in moontoaster.prettytimebugrepro.PrettyTimeTest
[ERROR] testFormatUnrounded(moontoaster.prettytimebugrepro.PrettyTimeTest)  Time elapsed: 0.004 s  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[]10 хвилин тому> but was:<[-]10 хвилин тому>
        at moontoaster.prettytimebugrepro.PrettyTimeTest.testFormatUnrounded(PrettyTimeTest.java:27)
moontoaster commented 3 months ago

I could write a pull request for this, should I?

lincolnthree commented 3 months ago

@moontoaster Hey! Thanks so much for submitting this issue. Absolutely a pull request would be VERY welcome for this! I appreciate your time and energy in finding this bug, writing a test, and offering to help.

Also feel free to add the new test as well!

Sorry for the delay - we've got a new baby in the house and are overloaded right now!

moontoaster commented 3 months ago

I have made a pull request. Congrats on the baby!

lincolnthree commented 3 months ago

@moontoaster Thank you! I will get this merged and released ASAP :D He's super cute already and takes soooo much time. I always "knew" but now I "know".

lincolnthree commented 2 months ago

Released 5.0.8.Final with this fix. It should be available in central as soon as it syncs from the Sonatype release server.

moontoaster commented 2 months ago

Thank you! Sorry for the late response, for some reason notifications don't show up in GitHub's UI

lincolnthree commented 2 months ago

You're very welcome :) Thank YOU for the fix!