diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2018-07-26 20:22:13 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2018-07-26 20:22:13 +0000 |
commit | 3739de6df80d0b20310c3c9d0fcab133fc734b0e (patch) | |
tree | 1c479477855d996101b78d75e82c749bf45b8c60 /src/main | |
parent | dd7b26018c0eacddc7681e48aee1c3cd1cf5c2a6 (diff) | |
download | jackcess-3739de6df80d0b20310c3c9d0fcab133fc734b0e.tar.gz jackcess-3739de6df80d0b20310c3c9d0fcab133fc734b0e.zip |
test TimeSerial; implement DateSerial
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1187 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java index 7bfb256..ac5313c 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java @@ -74,6 +74,31 @@ public class DefaultDateFunctions } }); + public static final Function DATESERIAL = registerFunc(new Func3("DateSerial") { + @Override + protected Value eval3(EvalContext ctx, Value param1, Value param2, Value param3) { + int year = param1.getAsLongInt(); + int month = param2.getAsLongInt(); + int day = param3.getAsLongInt(); + + // "default" two digit year handling + if(year < 100) { + year += ((year <= 29) ? 2000 : 1900); + } + + DateFormat fmt = BuiltinOperators.getDateFormatForType(ctx, Value.Type.DATE); + Calendar cal = fmt.getCalendar(); + cal.clear(); + + cal.set(Calendar.YEAR, year); + // convert to 0 based value + cal.set(Calendar.MONTH, month - 1); + cal.set(Calendar.DAY_OF_MONTH, day); + + return BuiltinOperators.toValue(Value.Type.DATE, cal.getTime(), fmt); + } + }); + public static final Function NOW = registerFunc(new Func0("Now") { @Override protected Value eval0(EvalContext ctx) { @@ -122,6 +147,14 @@ public class DefaultDateFunctions long totalSeconds = (hours * SECONDS_PER_HOUR) + (minutes * SECONDS_PER_MINUTE) + seconds; + if(totalSeconds < 0L) { + do { + totalSeconds += SECONDS_PER_DAY; + } while(totalSeconds < 0L); + } else if(totalSeconds > SECONDS_PER_DAY) { + totalSeconds %= SECONDS_PER_DAY; + } + DateFormat fmt = BuiltinOperators.getDateFormatForType(ctx, Value.Type.TIME); double dd = totalSeconds / DSECONDS_PER_DAY; return BuiltinOperators.toValue(Value.Type.TIME, dd, fmt); |