diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2018-07-25 02:30:33 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2018-07-25 02:30:33 +0000 |
commit | b2aba90126da7421be9d30656354dda71d0de301 (patch) | |
tree | 6897003b0d78208f3ded756380ba0db94be38d20 /src/main | |
parent | 0080d0c36f03edc4a9c6478fe439fe2dfd4d45ca (diff) | |
download | jackcess-b2aba90126da7421be9d30656354dda71d0de301.tar.gz jackcess-b2aba90126da7421be9d30656354dda71d0de301.zip |
add some date function tests
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1185 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java | 19 |
1 files changed, 14 insertions, 5 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 e60c956..7bfb256 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultDateFunctions.java @@ -155,9 +155,8 @@ public class DefaultDateFunctions public static final Function YEAR = registerFunc(new Func1NullIsNull("Year") { @Override protected Value eval1(EvalContext ctx, Value param1) { - // convert from 0 based to 1 based value return BuiltinOperators.toValue( - nonNullToCalendarField(ctx, param1, Calendar.YEAR) + 1); + nonNullToCalendarField(ctx, param1, Calendar.YEAR)); } }); @@ -186,11 +185,21 @@ public class DefaultDateFunctions return null; } int day = nonNullToCalendarField(ctx, param1, Calendar.DAY_OF_WEEK); + + // vbSunday (default) + int firstDay = 1; if(params.length > 1) { - // TODO handle first day of week - // int firstDay = params[1].getAsLong(); - throw new UnsupportedOperationException(); + firstDay = params[1].getAsLongInt(); + if(firstDay == 0) { + // 0 == vbUseSystem, so we will use the default "sunday" + firstDay = 1; + } } + + // shift all the values to 0 based to calculate the correct value, then + // back to 1 based to return the result + day = (((day - 1) - (firstDay - 1) + 7) % 7) + 1; + return BuiltinOperators.toValue(day); } }); |