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

Fix for formatDuration method for russian locale #260

Closed Snow4DV closed 1 year ago

Snow4DV commented 1 year ago

This PR partly addresses issue #259 for russian language:

In english locale formatDuration() method works correctly returning "12 days"/"1 week"/"1 year" and etc. format() method also returns the correct thing: "12 days ago"/"in 1 week"/"1 year ago" but there's was a problem with russian locale:

while method format returned "12 дней назад" (12 days ago)/"1 минуту назад" (1 minute ago) there was a problem with formatDuration (and it wasn't even included in unit tests) - it returned String.valueOf(12) or "12"/"1" instead of desired "12 дней"/"1 минута"

This PR fixes this problem for russian locale.

Some work should still be done to support this for kk, uk, pl locales - these locales basically shared the same code.

P.S. In order to distinguish "1 минута" (or "1 minute") received by formatDuration from "через 1 минуту"/( or "in 1 minute") {there are some other cases of this but there are really few of them} i used a little bit hacky solution so some changes might be considered so format method would receive some hint whether result would be decorated or not. Not really important - just a small note (see comment in the code)

Snow4DV commented 1 year ago

I am concerned about it because it caused issues for jerboa (lemmy client) when polish/russian/ukrainian users got incorrectly represented duration: https://github.com/dessalines/jerboa/issues/539

lincolnthree commented 1 year ago

Hey! Thank you for reporting this and for sending a PR. I will review it ASAP and get a new release put out if everything looks good. Much appreciated :)

lincolnthree commented 1 year ago

Just took a quick glance. Confirms my suspicions. Russian is a complicated language :D

Snow4DV commented 1 year ago

Yeah it is indeed :)) Same thing applies to Polish, Ukrainian

lincolnthree commented 1 year ago

@Snow4DV Any chance you know how to fix the other languages as well? Or know someone who does? :D Unfortunately I am not at all familiar with them, and I don't personally maintain the translations (by necessity, lol).

lincolnthree commented 1 year ago

Looks great, tests pass, let's go!

lincolnthree commented 1 year ago

Released 5.0.7.Final -- Should be in central overnight. Thank you again!!

Snow4DV commented 1 year ago

Great! :) Thank you for quick merge!)

Snow4DV commented 1 year ago

@Snow4DV Any chance you know how to fix the other languages as well? Or know someone who does? :D Unfortunately I am not at all familiar with them, and I don't personally maintain the translations (by necessity, lol).

I'll have a look at it soon - if i understood everything correctly, rules are pretty similar at least for polish and ukrainian to me. Will use translator to make sure :)