Skip to content

Commit

Permalink
Merge pull request #88 from mbaumbach/master
Browse files Browse the repository at this point in the history
Support unpadded hours and days
  • Loading branch information
bkiers authored May 26, 2018
2 parents 251e724 + b5568aa commit aae60e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/liqp/filters/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ public class Date extends Filter {
* %B - The full month name (``January'')
* %c - The preferred local date and time representation
* %d - Day of the month (01..31)
* %e - Day of the month (1..31)
* %H - Hour of the day, 24-hour clock (00..23)
* %I - Hour of the day, 12-hour clock (01..12)
* %j - Day of the year (001..366)
* %k - Hour of the day, 24-hour clock (0..23)
* %l - Hour of the day, 12-hour clock (0..12)
* %m - Month of the year (01..12)
* %M - Minute of the hour (00..59)
* %p - Meridian indicator (``AM'' or ``PM'')
Expand Down Expand Up @@ -145,6 +148,9 @@ private static void init() {

// %d - Day of the month (01..31)
LIQUID_TO_JAVA_FORMAT.put('d', new SimpleDateFormat("dd", locale));

// %e - Day of the month (1..31)
LIQUID_TO_JAVA_FORMAT.put('e', new SimpleDateFormat("d", locale));

// %H - Hour of the day, 24-hour clock (00..23)
LIQUID_TO_JAVA_FORMAT.put('H', new SimpleDateFormat("HH", locale));
Expand All @@ -154,6 +160,12 @@ private static void init() {

// %j - Day of the year (001..366)
LIQUID_TO_JAVA_FORMAT.put('j', new SimpleDateFormat("DDD", locale));

// %k - Hour of the day, 24-hour clock (0..23)
LIQUID_TO_JAVA_FORMAT.put('k', new SimpleDateFormat("H", locale));

// %l - Hour of the day, 12-hour clock (1..12)
LIQUID_TO_JAVA_FORMAT.put('l', new SimpleDateFormat("h", locale));

// %m - Month of the year (01..12)
LIQUID_TO_JAVA_FORMAT.put('m', new SimpleDateFormat("MM", locale));
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/liqp/filters/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ public void applyTest() throws RecognitionException {
{"{{" + seconds + " | date: '%B'}}", simpleDateFormat("MMMM").format(date)},
{"{{" + seconds + " | date: '%c'}}", simpleDateFormat("EEE MMM dd HH:mm:ss yyyy").format(date)},
{"{{" + seconds + " | date: '%d'}}", simpleDateFormat("dd").format(date)},
{"{{" + seconds + " | date: '%e'}}", simpleDateFormat("d").format(date)},
{"{{" + seconds + " | date: '%H'}}", simpleDateFormat("HH").format(date)},
{"{{" + seconds + " | date: '%I'}}", simpleDateFormat("hh").format(date)},
{"{{" + seconds + " | date: '%j'}}", simpleDateFormat("DDD").format(date)},
{"{{" + seconds + " | date: '%k'}}", simpleDateFormat("H").format(date)},
{"{{" + seconds + " | date: '%l'}}", simpleDateFormat("h").format(date)},
{"{{" + seconds + " | date: '%m'}}", simpleDateFormat("MM").format(date)},
{"{{" + seconds + " | date: '%M'}}", simpleDateFormat("mm").format(date)},
{"{{" + seconds + " | date: '%p'}}", simpleDateFormat("a").format(date)},
Expand Down

0 comments on commit aae60e2

Please sign in to comment.