From 6d1e438383db09bbc7e2780cc20f127f8ac2492e Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 18 Oct 2018 23:41:02 +0000 Subject: rework string conversion to date; add support for dates with implicit years; implement DatePart function git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1210 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/expr/TemporalConfig.java | 60 +++++- .../healthmarketscience/jackcess/expr/Value.java | 8 + .../jackcess/impl/expr/BaseDelayedValue.java | 4 + .../jackcess/impl/expr/BaseNumericValue.java | 14 +- .../jackcess/impl/expr/BaseValue.java | 20 +- .../jackcess/impl/expr/BuiltinOperators.java | 2 +- .../jackcess/impl/expr/DateTimeValue.java | 6 + .../jackcess/impl/expr/DefaultDateFunctions.java | 204 +++++++++++++++------ .../jackcess/impl/expr/DefaultFunctions.java | 51 ++++-- .../jackcess/impl/expr/DefaultNumberFunctions.java | 2 +- .../jackcess/impl/expr/ExpressionTokenizer.java | 123 ++++++++----- .../jackcess/impl/expr/FunctionSupport.java | 1 - .../jackcess/impl/expr/StringValue.java | 28 ++- .../jackcess/PropertyExpressionTest.java | 2 +- .../jackcess/impl/expr/DefaultFunctionsTest.java | 30 ++- 15 files changed, 417 insertions(+), 138 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java b/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java index d7061ca..b7de667 100644 --- a/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java +++ b/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java @@ -31,12 +31,14 @@ import java.util.Locale; public class TemporalConfig { public static final String US_DATE_FORMAT = "M/d/yyyy"; + public static final String US_DATE_IMPLICIT_YEAR_FORMAT = "M/d"; public static final String US_TIME_FORMAT_12 = "h:mm:ss a"; public static final String US_TIME_FORMAT_24 = "H:mm:ss"; /** default implementation which is configured for the US locale */ public static final TemporalConfig US_TEMPORAL_CONFIG = new TemporalConfig( - US_DATE_FORMAT, US_TIME_FORMAT_12, US_TIME_FORMAT_24, '/', ':', Locale.US); + US_DATE_FORMAT, US_DATE_IMPLICIT_YEAR_FORMAT, + US_TIME_FORMAT_12, US_TIME_FORMAT_24, '/', ':', Locale.US); public enum Type { DATE, TIME, DATE_TIME, TIME_12, TIME_24, DATE_TIME_12, DATE_TIME_24; @@ -74,9 +76,37 @@ public class TemporalConfig throw new RuntimeException("invalid type " + this); } } + + public boolean includesDate() { + switch(this) { + case DATE: + case DATE_TIME: + case DATE_TIME_12: + case DATE_TIME_24: + return true; + default: + return false; + } + } + + public boolean includesTime() { + return (this != DATE); + } + + public boolean isTimeOnly() { + switch(this) { + case TIME: + case TIME_12: + case TIME_24: + return true; + default: + return false; + } + } } private final String _dateFormat; + private final String _dateImplicitYearFormat; private final String _timeFormat12; private final String _timeFormat24; private final char _dateSeparator; @@ -92,6 +122,7 @@ public class TemporalConfig *