Dateformatting weird? or I'm not seeing something

can you please help me debug this?
I don’t see an issue in the code, just seems to me that Dateformatter acts weird.
OH 3.2.0 on docker.

val alltime  = now.withHour(0).withMinute(0).withMonth(1).withDayOfMonth(1).withYear(2020)
    
gMinMaxAlltime.members.forEach[ ItemName |
        
        val myItem = ScriptServiceUtil.getItemRegistry.getItem(ItemName.name)

        // min/max alltime
        val maxA = (myItem.maximumSince(alltime))
        val minA = (myItem.minimumSince(alltime))

        logInfo("max",maxA.getTimestamp.toString)
        logInfo("max",maxA.getTimestamp.format(DateTimeFormatter.ofPattern("HH:mm, dd.MM YYYY")).toString)
        logInfo("min",minA.getTimestamp.toString)
        logInfo("min",minA.getTimestamp.format(DateTimeFormatter.ofPattern("HH:mm, dd.MM YYYY")).toString)
]

outputs:

2022-02-15 11:34:26.584 [INFO ] [org.openhab.core.model.script.max   ] - 2021-06-20T16:40:00.657+02:00[Europe/Prague]
2022-02-15 11:34:26.585 [INFO ] [org.openhab.core.model.script.max   ] - 16:40, 20.06 2021
2022-02-15 11:34:26.586 [INFO ] [org.openhab.core.model.script.min   ] - 2021-12-26T05:40:07.530+01:00[Europe/Prague]
2022-02-15 11:34:26.588 [INFO ] [org.openhab.core.model.script.min   ] - 05:40, 26.12 2022
2022-02-15 11:34:30.008 [INFO ] [org.openhab.core.model.script.max   ] - 2021-06-21T20:20:00.657+02:00[Europe/Prague]
2022-02-15 11:34:30.010 [INFO ] [org.openhab.core.model.script.max   ] - 20:20, 21.06 2021
2022-02-15 11:34:30.011 [INFO ] [org.openhab.core.model.script.min   ] - 2022-01-21T22:00:15.069+01:00[Europe/Prague]
2022-02-15 11:34:30.013 [INFO ] [org.openhab.core.model.script.min   ] - 22:00, 21.01 2022

as you can see, only one item has got 2021-12-26 formatted as 26.12 2022 and rest of the items are formatted correctly with their years.

any clue why??

Use yyyy instead of YYYY.

It’s something, you need to know (or to read the java documentation carefully): DateTimeFormatter (Java Platform SE 8 )

Y week-based-year year 1996; 96
y year-of-era year 2004; 04

It’s only a difference in very few days in a year (which makes it very tricky to spot it). Only when the week of day belongs to an other year compared to the day itself.

1 Like

Thank you very much, solved!
very tricky :slight_smile: