Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[240] Accept dates without time #242

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/liqp/filters/date/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class Parser {
datePatterns.add("yyyy-MM-dd HH:mm:ss z");
datePatterns.add("yyyy-MM-dd'T'HH:mm:ss z");
datePatterns.add("EEE MMM dd hh:mm:ss yyyy");
datePatterns.add("yyyy-MM-dd");
datePatterns.add("dd-MM-yyyy");
}

public static ZonedDateTime parse(String str, Locale locale, ZoneId defaultZone) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/liqp/filters/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import liqp.filters.date.CustomDateFormatSupport;
import liqp.parser.Flavor;
import org.antlr.v4.runtime.RecognitionException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import ua.co.k.strftime.formatters.HybridFormat;
Expand Down Expand Up @@ -211,4 +212,11 @@ public void test171() {
String result = t.render(values);
assertEquals("Space: 2020 | T: 2020", result);
}

@Test
public void test240() {
assertEquals("10-13", Template.parse("{{ \"2022-10-13 12:06:04\" | date: \"%m-%e\" }}").render());
assertEquals("10-13", Template.parse("{{ \"2022-10-13\" | date: \"%m-%e\" }}").render());
assertEquals("10-13", Template.parse("{{ \"13-10-2022\" | date: \"%m-%e\" }}").render());
}
}