-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aeab22e
commit 428f1f3
Showing
8 changed files
with
215 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/liqp/filters/date/fuzzy/extractors/EnglishDMYPatternExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package liqp.filters.date.fuzzy.extractors; | ||
|
||
import java.util.regex.Matcher; | ||
|
||
class EnglishDMYPatternExtractor extends RegexPartExtractor { | ||
public EnglishDMYPatternExtractor() { | ||
super("(?:^|.*?\\D)" | ||
+ "(?<day>0?[1-9]|[12][0-9]|3[01])" | ||
+ "/" | ||
+ "(?<month>0?[1-9]|1[0-2])" | ||
+ "/" | ||
+ "(?<year>\\d{2}|\\d{4})" | ||
+ "(?:$|\\D.*?)", null); | ||
} | ||
|
||
|
||
@Override | ||
public PartExtractorResult extract(String source) { | ||
Matcher matcher = pattern.matcher(source); | ||
if (matcher.find()) { | ||
PartExtractorResult result = new PartExtractorResult(); | ||
result.found = true; | ||
result.start = matcher.start("day"); | ||
result.end = matcher.end("year"); | ||
result.formatterPattern = getPattern(matcher); | ||
return result; | ||
} | ||
return new PartExtractorResult(); | ||
} | ||
|
||
private String getPattern(Matcher matcher) { | ||
StringBuilder sbfp = new StringBuilder(); | ||
if (matcher.group("day").length() == 1) { | ||
sbfp.append("d"); | ||
} else { | ||
sbfp.append("dd"); | ||
} | ||
sbfp.append("/"); | ||
if (matcher.group("month").length() == 1) { | ||
sbfp.append("M"); | ||
} else { | ||
sbfp.append("MM"); | ||
} | ||
sbfp.append("/"); | ||
if (matcher.group("year").length() == 2) { | ||
sbfp.append("yy"); | ||
} else { | ||
sbfp.append("yyyy"); | ||
} | ||
return sbfp.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/liqp/filters/date/fuzzy/extractors/ISO8601YMDPatternExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package liqp.filters.date.fuzzy.extractors; | ||
|
||
import java.util.regex.Matcher; | ||
|
||
class ISO8601YMDPatternExtractor extends RegexPartExtractor { | ||
|
||
public ISO8601YMDPatternExtractor() { | ||
super("(?:^|.*?\\D)" | ||
+ "(?<year>\\d{4})-(?<month>0?[1-9]|1[0-2])-(?<date>0?[1-9]|[12][0-9]|3[01])" | ||
+ "(?:$|\\D.*?)", null); | ||
} | ||
|
||
@Override | ||
public PartExtractorResult extract(String source) { | ||
Matcher matcher = pattern.matcher(source); | ||
if (matcher.find()) { | ||
PartExtractorResult result = new PartExtractorResult(); | ||
result.found = true; | ||
result.start = matcher.start("year"); | ||
result.end = matcher.end("date"); | ||
result.formatterPattern = getPattern(matcher); | ||
return result; | ||
} | ||
return new PartExtractorResult(); | ||
} | ||
|
||
private String getPattern(Matcher matcher) { | ||
StringBuilder sbfp = new StringBuilder("yyyy"); | ||
sbfp.append("-"); | ||
if (matcher.group("month").length() == 1) { | ||
sbfp.append("M"); | ||
} else { | ||
sbfp.append("MM"); | ||
} | ||
sbfp.append("-"); | ||
if (matcher.group("date").length() == 1) { | ||
sbfp.append("d"); | ||
} else { | ||
sbfp.append("dd"); | ||
} | ||
return sbfp.toString(); | ||
} | ||
} |
Oops, something went wrong.