ocpsoft / prettytime

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

Rounding rules are not ignored if locale is de #218

Open caad1229 opened 3 years ago

caad1229 commented 3 years ago

Hi, Calling the formatUnrounded method will ignore the rounding when I use the German format.

Therefore, rounding is effective and the expected value cannot be obtained. Below is a test snippet.

    @Test
    fun diffTime_de() {
        val from = Date(2021, 5, 1, 23, 45, 0)
        // just ago 1min
        val to1 = Date(2021, 5, 1, 23, 44, 0)
        // ago 1min 59sec
        val to2 = Date(2021, 5, 1, 23, 43, 1)

        // set locale to de
        val diffTime = PrettyTime(Locale.GERMAN).setReference(from)

        // > success
        assertEquals("vor 1 Minute", diffTime.format(to1))
        // > success
        assertEquals("vor 1 Minute", diffTime.formatUnrounded(to1))

        // > success
        assertEquals("vor 2 Minuten", diffTime.format(to2))
        // > failed : Actual "vor 1 Minuten"
        assertEquals("vor 1 Minute", diffTime.formatUnrounded(to2))
    }

Best regards

lincolnthree commented 3 years ago

Hey @caad1229,

Thanks so much for the issue report. This is an interesting one. Since you've already dug around in the internals a bit, any chance you feel like sending a PR for this? I'd be happy to get it merged if you get this fixed :)

Based on the fact that this is calling a super class, I'm wondering if this potentially an issue with other languages as well? Or do you feel this is only an issue with German?

Cheers! ~Lincoln

ShareASmile commented 1 year ago

Hi, @lincolnthree would this issue be taken care of by yourself ! It is there for quite a while.

lincolnthree commented 10 months ago

@ShareASmile As this only impacts very specific usage of the German translation, it is not very high priority. PRs welcome. Thanks!