-
Notifications
You must be signed in to change notification settings - Fork 96
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
b184c83
commit 7e66c66
Showing
7 changed files
with
97 additions
and
122 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
76 changes: 76 additions & 0 deletions
76
src/main/java/liqp/filters/date/fuzzy/extractors/AllYMDPatternExtractor.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,76 @@ | ||
package liqp.filters.date.fuzzy.extractors; | ||
|
||
import static liqp.filters.date.fuzzy.extractors.AnyYMDPatternExtractor.pD; | ||
import static liqp.filters.date.fuzzy.extractors.AnyYMDPatternExtractor.pM; | ||
import static liqp.filters.date.fuzzy.extractors.AnyYMDPatternExtractor.pY2; | ||
import static liqp.filters.date.fuzzy.extractors.AnyYMDPatternExtractor.pY4; | ||
import static liqp.filters.date.fuzzy.extractors.AnyYMDPatternExtractor.pp; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import liqp.filters.date.fuzzy.PartExtractor; | ||
|
||
public class AllYMDPatternExtractor implements PartExtractor { | ||
|
||
private final List<AnyYMDPatternExtractor> extractors = new ArrayList<>(); | ||
|
||
public AllYMDPatternExtractor() { | ||
AnyYMDPatternExtractor iSO8601Y4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY4(), pp("-"), pM(), pp("-"), pD()); // yyyy-MM-dd | ||
extractors.add(iSO8601Y4MDPatternExtractor); | ||
AnyYMDPatternExtractor americanY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pM(), pp("/"), pD(), pp("/"), pY4()); // MM/dd/yyyy | ||
extractors.add(americanY4MDPatternExtractor); | ||
// next are top-rated locale formats, according to gpt | ||
AnyYMDPatternExtractor indianY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pD(), pp("-"), pM(), pp("-"), pY4()); // d-M-yyyy | ||
extractors.add(indianY4MDPatternExtractor); | ||
AnyYMDPatternExtractor chineseY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY4(), pp("/"), pM(), pp("/"), pD()); // yyyy/M/d | ||
extractors.add(chineseY4MDPatternExtractor); | ||
AnyYMDPatternExtractor englishY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pD(), pp("/"), pM(), pp("/"), pY4()); // d/M/yyyy | ||
extractors.add(englishY4MDPatternExtractor); | ||
AnyYMDPatternExtractor slavicY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pD(), pp("."), pM(), pp("."), pY4()); | ||
extractors.add(slavicY4MDPatternExtractor); | ||
AnyYMDPatternExtractor coldEuropeY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY4(), pp("-"), pM(), pp("-"), pD()); // yyyy-MM-dd | ||
extractors.add(coldEuropeY4MDPatternExtractor); | ||
AnyYMDPatternExtractor espanaY4MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY4(), pp("-"), pM(), pp("-"), pD()); // yyyy/MM/dd | ||
extractors.add(espanaY4MDPatternExtractor); | ||
AnyYMDPatternExtractor americanY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pM(), pp("/"), pD(), pp("/"), pY4()); // MM/dd/yy | ||
extractors.add(americanY2MDPatternExtractor); | ||
AnyYMDPatternExtractor indianY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pD(), pp("-"), pM(), pp("-"), pY2()); // d-M-yy | ||
extractors.add(indianY2MDPatternExtractor); | ||
AnyYMDPatternExtractor chineseY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY2(), pp("/"), pM(), pp("/"), pD()); // yyyy/M/d | ||
extractors.add(chineseY2MDPatternExtractor); | ||
AnyYMDPatternExtractor englishY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pD(), pp("/"), pM(), pp("/"), pY2()); // d/M/yy | ||
extractors.add(englishY2MDPatternExtractor); | ||
AnyYMDPatternExtractor slavicY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pD(), pp("."), pM(), pp("."), pY2()); | ||
extractors.add(slavicY2MDPatternExtractor); | ||
AnyYMDPatternExtractor coldEuropeY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY2(), pp("-"), pM(), pp("-"), pD()); // yy-MM-dd | ||
extractors.add(coldEuropeY2MDPatternExtractor); | ||
AnyYMDPatternExtractor espanaY2MDPatternExtractor = new AnyYMDPatternExtractor( | ||
pY2(), pp("-"), pM(), pp("-"), pD()); // yy/MM/dd | ||
extractors.add(espanaY2MDPatternExtractor); | ||
} | ||
|
||
@Override | ||
public PartExtractorResult extract(String source) { | ||
for (AnyYMDPatternExtractor extractor : extractors) { | ||
PartExtractorResult result = extractor.extract(source); | ||
if (result.found) { | ||
return result; | ||
} | ||
} | ||
return new PartExtractorResult(); | ||
} | ||
} |
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
7 changes: 0 additions & 7 deletions
7
src/main/java/liqp/filters/date/fuzzy/extractors/EnglishDMYPatternExtractor.java
This file was deleted.
Oops, something went wrong.
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: 0 additions & 43 deletions
43
src/main/java/liqp/filters/date/fuzzy/extractors/ISO8601YMDPatternExtractor.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
src/test/java/liqp/filters/date/fuzzy/extractors/EnglishDMYPatternExtractorTest.java
This file was deleted.
Oops, something went wrong.