aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/healthmarketscience/jackcess/expr
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-11-13 04:59:29 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-11-13 04:59:29 +0000
commitac6811e50d1f32a4eb14785282099c316dcfc7fd (patch)
tree89e1131802c32bb0b9ac39cc6510dabcfe6eaecd /src/main/java/com/healthmarketscience/jackcess/expr
parent25069267ebe8d5f9028d51c2fbe7fb0217e5a07f (diff)
downloadjackcess-ac6811e50d1f32a4eb14785282099c316dcfc7fd.tar.gz
jackcess-ac6811e50d1f32a4eb14785282099c316dcfc7fd.zip
implement FormatDateTime function
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1221 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/expr')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java82
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/expr/package-info.java8
2 files changed, 74 insertions, 16 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java b/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java
index b7de667..db7806f 100644
--- a/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java
+++ b/src/main/java/com/healthmarketscience/jackcess/expr/TemporalConfig.java
@@ -32,28 +32,42 @@ 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";
+ public static final String US_TIME_FORMAT_12_FORMAT = "h:mm:ss a";
+ public static final String US_TIME_FORMAT_24_FORMAT = "H:mm:ss";
+ public static final String US_LONG_DATE_FORMAT = "EEEE, MMMM dd, yyyy";
+
+ public static final String MEDIUM_DATE_FORMAT = "dd-MMM-yy";
+ public static final String MEDIUM_TIME_FORMAT = "hh:mm a";
+ public static final String SHORT_TIME_FORMAT = "HH:mm";
/** default implementation which is configured for the US locale */
public static final TemporalConfig US_TEMPORAL_CONFIG = new TemporalConfig(
- US_DATE_FORMAT, US_DATE_IMPLICIT_YEAR_FORMAT,
- US_TIME_FORMAT_12, US_TIME_FORMAT_24, '/', ':', Locale.US);
+ US_DATE_FORMAT, US_DATE_IMPLICIT_YEAR_FORMAT, US_LONG_DATE_FORMAT,
+ US_TIME_FORMAT_12_FORMAT, US_TIME_FORMAT_24_FORMAT, '/', ':', Locale.US);
public enum Type {
- DATE, TIME, DATE_TIME, TIME_12, TIME_24, DATE_TIME_12, DATE_TIME_24;
+ DATE, TIME, DATE_TIME, TIME_12, TIME_24, DATE_TIME_12, DATE_TIME_24,
+ GENERAL_DATE, LONG_DATE, MEDIUM_DATE, SHORT_DATE,
+ LONG_TIME, MEDIUM_TIME, SHORT_TIME;
public Type getDefaultType() {
switch(this) {
case DATE:
+ case LONG_DATE:
+ case MEDIUM_DATE:
+ case SHORT_DATE:
return DATE;
case TIME:
case TIME_12:
case TIME_24:
+ case LONG_TIME:
+ case MEDIUM_TIME:
+ case SHORT_TIME:
return TIME;
case DATE_TIME:
case DATE_TIME_12:
case DATE_TIME_24:
+ case GENERAL_DATE:
return DATE_TIME;
default:
throw new RuntimeException("invalid type " + this);
@@ -63,41 +77,55 @@ public class TemporalConfig
public Value.Type getValueType() {
switch(this) {
case DATE:
+ case LONG_DATE:
+ case MEDIUM_DATE:
+ case SHORT_DATE:
return Value.Type.DATE;
case TIME:
case TIME_12:
case TIME_24:
+ case LONG_TIME:
+ case MEDIUM_TIME:
+ case SHORT_TIME:
return Value.Type.TIME;
case DATE_TIME:
case DATE_TIME_12:
case DATE_TIME_24:
+ case GENERAL_DATE:
return Value.Type.DATE_TIME;
default:
throw new RuntimeException("invalid type " + this);
}
}
+ public boolean includesTime() {
+ return !isDateOnly();
+ }
+
public boolean includesDate() {
+ return !isTimeOnly();
+ }
+
+ public boolean isDateOnly() {
switch(this) {
case DATE:
- case DATE_TIME:
- case DATE_TIME_12:
- case DATE_TIME_24:
+ case LONG_DATE:
+ case MEDIUM_DATE:
+ case SHORT_DATE:
return true;
default:
return false;
}
}
- public boolean includesTime() {
- return (this != DATE);
- }
-
public boolean isTimeOnly() {
switch(this) {
case TIME:
case TIME_12:
case TIME_24:
+ case LONG_TIME:
+ case MEDIUM_TIME:
+ case SHORT_TIME:
return true;
default:
return false;
@@ -107,6 +135,7 @@ public class TemporalConfig
private final String _dateFormat;
private final String _dateImplicitYearFormat;
+ private final String _longDateFormat;
private final String _timeFormat12;
private final String _timeFormat24;
private final char _dateSeparator;
@@ -135,11 +164,13 @@ public class TemporalConfig
* dateSeparator.
*/
public TemporalConfig(String dateFormat, String dateImplicitYearFormat,
+ String longDateFormat,
String timeFormat12, String timeFormat24,
char dateSeparator, char timeSeparator, Locale locale)
{
_dateFormat = dateFormat;
_dateImplicitYearFormat = dateImplicitYearFormat;
+ _longDateFormat = longDateFormat;
_timeFormat12 = timeFormat12;
_timeFormat24 = timeFormat24;
_dateSeparator = dateSeparator;
@@ -192,12 +223,15 @@ public class TemporalConfig
public String getDateTimeFormat(Type type) {
switch(type) {
case DATE:
+ case SHORT_DATE:
return getDefaultDateFormat();
case TIME:
return getDefaultTimeFormat();
case DATE_TIME:
+ case GENERAL_DATE:
return getDefaultDateTimeFormat();
case TIME_12:
+ case LONG_TIME:
return getTimeFormat12();
case TIME_24:
return getTimeFormat24();
@@ -205,6 +239,14 @@ public class TemporalConfig
return getDateTimeFormat12();
case DATE_TIME_24:
return getDateTimeFormat24();
+ case LONG_DATE:
+ return getLongDateFormat();
+ case MEDIUM_DATE:
+ return getMediumDateFormat();
+ case MEDIUM_TIME:
+ return getMediumTimeFormat();
+ case SHORT_TIME:
+ return getShortTimeFormat();
default:
throw new IllegalArgumentException("unknown date/time type " + type);
}
@@ -233,4 +275,20 @@ public class TemporalConfig
private static String toDateTimeFormat(String dateFormat, String timeFormat) {
return dateFormat + " " + timeFormat;
}
+
+ protected String getLongDateFormat() {
+ return _longDateFormat;
+ }
+
+ protected String getMediumDateFormat() {
+ return MEDIUM_DATE_FORMAT;
+ }
+
+ protected String getMediumTimeFormat() {
+ return MEDIUM_TIME_FORMAT;
+ }
+
+ protected String getShortTimeFormat() {
+ return SHORT_TIME_FORMAT;
+ }
}
diff --git a/src/main/java/com/healthmarketscience/jackcess/expr/package-info.java b/src/main/java/com/healthmarketscience/jackcess/expr/package-info.java
index 048e606..28d9a86 100644
--- a/src/main/java/com/healthmarketscience/jackcess/expr/package-info.java
+++ b/src/main/java/com/healthmarketscience/jackcess/expr/package-info.java
@@ -101,10 +101,10 @@ limitations under the License.
* <tr class="TableRowColor"><td>Chr</td><td>Y</td></tr>
* <tr class="TableRowColor"><td>ChrW</td><td>Y</td></tr>
* <tr class="TableRowColor"><td>EuroConvert</td><td></td></tr>
- * <tr class="TableRowColor"><td>FormatCurrency</td><td></td></tr>
- * <tr class="TableRowColor"><td>FormatDateTime</td><td></td></tr>
- * <tr class="TableRowColor"><td>FormatNumber</td><td></td></tr>
- * <tr class="TableRowColor"><td>FormatPercent</td><td></td></tr>
+ * <tr class="TableRowColor"><td>FormatCurrency</td><td>Y</td></tr>
+ * <tr class="TableRowColor"><td>FormatDateTime</td><td>Y</td></tr>
+ * <tr class="TableRowColor"><td>FormatNumber</td><td>Y</td></tr>
+ * <tr class="TableRowColor"><td>FormatPercent</td><td>Y</td></tr>
* <tr class="TableRowColor"><td>GUIDFromString</td><td></td></tr>
* <tr class="TableRowColor"><td>Hex[$]</td><td>Y</td></tr>
* <tr class="TableRowColor"><td>Nz</td><td>Y</td></tr>