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

Some languages do not provide time units when formatting a duration #259

Open lbenedetto opened 1 year ago

lbenedetto commented 1 year ago

Polish (pl), Russian (ru), Ukrainian (uk), and Kazakh (kk) do not provide time units when formatting a duration.

    @Test fun testPL() = testPrettyTimeFails(Locale("pl"))
    @Test fun testRU() = testPrettyTimeFails(Locale("ru"))
    @Test fun testUK() = testPrettyTimeFails(Locale("uk"))
    @Test fun testKK() = testPrettyTimeFails(Locale("kk"))

    private fun testPrettyTimeFails(locale: Locale) {
        val date = Date.from(Instant.now().minus(Duration.ofDays(1)))
        val durationString = PrettyTime(locale).formatDuration(date)
        assertNotEquals("1", durationString)
    }

This is because these four languages override TimeFormat::format with an implementation similar to this:

@Override
public String format(Duration duration)
{
    long quantity = duration.getQuantityRounded(tolerance);
    return String.valueOf(quantity);
}
lincolnthree commented 1 year ago

@lbenedetto Hey, thanks for reporting - and @Snow4DV thanks for fixing (for Russian). Hoping you can also work on the others! I am unfortunately not familiar with these languages!