Post age has no unit
** Jerboa Version ** 0.0.33
Describe the bug Post age has no unit - shows just a number without an indication whether that's seconds, minutes, hours etc.
To Reproduce Happens every single time if my phone's language is set to Polish.
I'm experiencing the same bug, phone set to Polish as well.
I have to go to sleep, but I figured I'd share what I found -
I tried 5 languages (English, Spanish, Polish, Korean, and Danish) and Polish was the only one that triggered this issue.
What's interesting is that, of these languages, Polish is the only locale for which override is defined in org.ocpsoft.prettytime.impl.ResourcesTimeFormat:L112:
return override == null ? super.format(duration) : override.format(duration);
For Polish, this override takes us to org.ocpsoft.prettytime.i18n.Resources_pl:L48, where only the number is returned:
public String format(Duration duration)
{
long quantity = duration.getQuantityRounded(tolerance);
return String.valueOf(quantity);
}
as opposed to org.ocpsoft.prettytime.format.SimpleTimeFormat:L95, which is where we go when there is no override above.
private String format(final Duration duration, final boolean round)
{
String sign = getSign(duration);
String unit = getGramaticallyCorrectName(duration, round);
long quantity = getQuantity(duration, round);
return applyPattern(sign, unit, quantity);
}
Update: Okay, I got curious and tried Russian. It, too, has an override there, and it too has missing time units. So format() behaves differently for languages with override ResourceBundles, and from what I can see it will never return the time unit.
Double update: If you look at the Resources_*.java files for languages that have overrides vs. no overrides, you see that the ones that work properly (no override) are mostly just a big 2D array with mapped out values. I grepped in that directory and it seems like there should be 4 languages that will have this issue: Kazakh, Polish, Russian, and Slavic.
I've filed a bug report with PrettyTime https://github.com/ocpsoft/prettytime/issues/259
This might be happening because Polish has different plurals for different numbers.
1 sekunda, 2..4 sekundy, 5.. sekund
This might be happening because Polish has different plurals for different numbers.
1 sekunda, 2..4 sekundy, 5.. sekund
It is already implemented for polish here: https://github.com/ocpsoft/prettytime/blob/master/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_pl.java same thing for russian: https://github.com/ocpsoft/prettytime/blob/master/core/src/main/java/org/ocpsoft/prettytime/i18n/Resources_ru.java
There's probably a bug hiding somewhere
upd: Oh, ok, now i don't get why it was implemented but still returns simple String.valueOf in format override. Still looking into it
sensiblepuffin already explained what's wrong. It's because those four languages override TimeFormat::format and just return back the number passed in without attempting any logic. The implementation doesn't work because it doesn't exist. Look at what other languages, like Japanese do in their override to see how it should look.
sensiblepuffin already explained what's wrong. It's because those four languages override
TimeFormat::formatand just return back the number passed in without attempting any logic. The implementation doesn't work because it doesn't exist. Look at what other languages, like Japanese do in their override to see how it should look.
I see but i'm more curious how did it happen in the first place. There's issue that shows it working correctly in the newpipe some time ago: https://github.com/ocpsoft/prettytime/issues/182 and nothing was changed in the code really since then in Resources_ru
Ok i looked into it and i discovered that while "formatDuration" is not implemented correctly in russian (and probably other languages) - format that basically return "1 hour ago" and etc works fine - that's what they used in NewPipe instead of "format" method. This unit test of library works totally fine:
public void testMinutesAgo3() throws Exception
{
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale);
assertEquals("12 минут назад", t.formatUnrounded(new Date(0)));
assertEquals("12 минут назад", t.format(new Date(0)));
}
@Test
public void testHoursAgo1() throws Exception
{
PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60), locale);
assertEquals("1 час назад", t.formatUnrounded(new Date(0)));
assertEquals("1 час назад", t.format(new Date(0)));
}
So just using "format" for these languages might be a better workaround
I solved this issue for ru locale in this pull request: https://github.com/ocpsoft/prettytime/pull/260 Apparently it was done because there are some cases in russian that were impossible to support in current architecture without a little bit of hacky solution (but it is pretty much fine here - not a big deal) - while in english "1 minute " and "1 minute ago" are barely the same thing in russian it is "1 минута" and "1 минуту назад"
Methods "format*" and "decorate*" were behaving incorrectly with old implementation: "format*" was used to get string value of date and "decorate*" was used to do the rest of the stuff. Correct way is to implement "format*" to return something like "12 days" and "decorate*" to add " ago" or "in " suffix/prefix.
This doesn't seem to be an issue anymore.