bkiers / Liqp

An ANTLR based 'Liquid Template' parser and rendering engine.
MIT License
165 stars 94 forks source link

Support for Instant, LocalDateTime date pattern #298

Closed bruce-igaw closed 7 months ago

bruce-igaw commented 9 months ago

I tried to render the Instant value through BlockNode, but I found a phenomenon in which time and minutes were incorrectly replaced. It seems that the problem is caused by the absence of the Instant’s date pattern in liqp/filters/date/Parser.java.

In the following code, only YEAR, MONTH_OF_YEAR, DAY_OF_MONTH, and SECOND_OF_MINUTE are True in isSupported(), while HOUR_OF_DAY and MINUTE_OF_HOUR are False.

        TemporalField[] copyThese = new TemporalField[]{
                YEAR,
                MONTH_OF_YEAR,
                DAY_OF_MONTH,
                HOUR_OF_DAY,
                MINUTE_OF_HOUR,
                SECOND_OF_MINUTE,
                NANO_OF_SECOND
        };
        for (TemporalField tf: copyThese) {
            if (temporalAccessor.isSupported(tf)) {
                now = now.with(tf, temporalAccessor.get(tf));
            }
        }

Perhaps it will be solved by adding the following patterns to datePatterns. (If there's a better way, that's good.)

datePatterns.add("yyyy-MM-dd'T'HH:mm:ss'Z'");
datePatterns.add("yyyy-MM-dd'T'HH:mm:ss");

When the above datePatterns were added, the Instant value was properly rendered. (tested Kotlin Code)

The following is the value that appears when instant is debugged in IntelliJ.

val beginDateInstant = Instant.ofEpochSecond(1704898800)

image

It is possible that I am not familiar with the usage. If there's right way in this case, would appreciate let me know. Temporarily convert Instant and LocalDateTime into String and use it.

msangel commented 9 months ago

Bug accepted. Working on fix. Thanks!