jerboa icon indicating copy to clipboard operation
jerboa copied to clipboard

Post age has no unit

Open axelrechenberg opened this issue 2 years ago • 4 comments

** 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.

Screenshot_2023-06-11-21-48-12-32_a10f969cf1c4adf2c503042b459b8476

axelrechenberg avatar Jun 11 '23 20:06 axelrechenberg

Screenshot_20230611_220109_Jerboa for Lemmy I'm experiencing the same bug, phone set to Polish as well.

gressen avatar Jun 11 '23 21:06 gressen

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.

sensiblepuffin avatar Jun 12 '23 03:06 sensiblepuffin

I've filed a bug report with PrettyTime https://github.com/ocpsoft/prettytime/issues/259

lbenedetto avatar Jun 15 '23 22:06 lbenedetto

This might be happening because Polish has different plurals for different numbers.

1 sekunda, 2..4 sekundy, 5.. sekund

dawid2193487 avatar Jun 21 '23 16:06 dawid2193487

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

Snow4DV avatar Jun 21 '23 18:06 Snow4DV

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.

lbenedetto avatar Jun 21 '23 18:06 lbenedetto

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.

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

Snow4DV avatar Jun 21 '23 18:06 Snow4DV

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

Snow4DV avatar Jun 21 '23 19:06 Snow4DV

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.

Snow4DV avatar Jun 22 '23 13:06 Snow4DV

This doesn't seem to be an issue anymore.

dessalines avatar Feb 10 '24 21:02 dessalines