1
0
Fork 0

fixed tests

This commit is contained in:
Jan Steemann 2015-09-14 11:55:39 +02:00
parent 4158f7d12b
commit 0c77b4fbe1
2 changed files with 51 additions and 38 deletions

View File

@ -4955,9 +4955,9 @@ function DATE_CALC (value, amount, unit, func) {
var sign = (func === "DATE_ADD" || func === undefined) ? 1 : -1;
var m;
// if amount is not a number, than it must be an ISO duration string
if (TYPEWEIGHT(amount) !== TYPEWEIGHT_NUMBER) {
if (TYPEWEIGHT(unit) !== TYPEWEIGHT_STRING) {
// if amount is not a number, then it must be an ISO duration string
if (TYPEWEIGHT(unit) === TYPEWEIGHT_NULL) {
if (TYPEWEIGHT(amount) !== TYPEWEIGHT_STRING) {
WARN(func, INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
return null;
}
@ -4996,6 +4996,10 @@ function DATE_CALC (value, amount, unit, func) {
WARN(func, INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
return null;
}
if (TYPEWEIGHT(amount) !== TYPEWEIGHT_NUMBER) {
WARN(func, INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH);
return null;
}
m = unitMapping[unit.toLowerCase()]; // we're sure unit is a string here
if (m === "undefined") {
WARN(func, INTERNAL.errors.ERROR_QUERY_INVALID_DATE_VALUE);
@ -5159,26 +5163,26 @@ function AQL_DATE_FORMAT (value, format) {
var yr = date.getUTCFullYear();
var offset = yr < 0 || yr > 9999 ? 3 : 0;
var dateMap = {
"%t": function(){ return date.getTime() },
"%z": function(){ return dateStr },
"%w": function(){ return AQL_DATE_DAYOFWEEK(dateStr) },
"%y": function(){ return dateStr.slice(0, 4 + offset) },
"%m": function(){ return dateStr.slice(5 + offset, 7 + offset) },
"%d": function(){ return dateStr.slice(8 + offset, 10 + offset) },
"%h": function(){ return dateStr.slice(11 + offset, 13 + offset) },
"%i": function(){ return dateStr.slice(14 + offset, 16 + offset) },
"%s": function(){ return dateStr.slice(17 + offset, 19 + offset) },
"%f": function(){ return dateStr.slice(20 + offset, 23 + offset) },
"%x": function(){ return zeropad(AQL_DATE_DAYOFYEAR(dateStr), 3) },
"%k": function(){ return zeropad(AQL_DATE_ISOWEEK(dateStr), 2) },
"%l": function(){ return +AQL_DATE_LEAPYEAR(dateStr) },
"%q": function(){ return AQL_DATE_QUARTER(dateStr) },
"%a": function(){ return zeropad(AQL_DATE_DAYS_IN_MONTH(dateStr), 2) },
"%n": function(){ return monthNames[date.getUTCMonth()] },
"%o": function(){ return monthNames[date.getUTCMonth()].substring(0, 3) },
"%e": function(){ return weekdayNames[AQL_DATE_DAYOFWEEK(dateStr)] },
"%g": function(){ return weekdayNames[AQL_DATE_DAYOFWEEK(dateStr)].substring(0, 3) },
"%%": function(){ return "%" } // Allow for literal "%Y" using "%%Y"
"%t": function(){ return date.getTime(); },
"%z": function(){ return dateStr; },
"%w": function(){ return AQL_DATE_DAYOFWEEK(dateStr); },
"%y": function(){ return dateStr.slice(0, 4 + offset); },
"%m": function(){ return dateStr.slice(5 + offset, 7 + offset); },
"%d": function(){ return dateStr.slice(8 + offset, 10 + offset); },
"%h": function(){ return dateStr.slice(11 + offset, 13 + offset); },
"%i": function(){ return dateStr.slice(14 + offset, 16 + offset); },
"%s": function(){ return dateStr.slice(17 + offset, 19 + offset); },
"%f": function(){ return dateStr.slice(20 + offset, 23 + offset); },
"%x": function(){ return zeropad(AQL_DATE_DAYOFYEAR(dateStr), 3); },
"%k": function(){ return zeropad(AQL_DATE_ISOWEEK(dateStr), 2); },
"%l": function(){ return +AQL_DATE_LEAPYEAR(dateStr); },
"%q": function(){ return AQL_DATE_QUARTER(dateStr); },
"%a": function(){ return zeropad(AQL_DATE_DAYS_IN_MONTH(dateStr), 2); },
"%n": function(){ return monthNames[date.getUTCMonth()]; },
"%o": function(){ return monthNames[date.getUTCMonth()].substring(0, 3); },
"%e": function(){ return weekdayNames[AQL_DATE_DAYOFWEEK(dateStr)]; },
"%g": function(){ return weekdayNames[AQL_DATE_DAYOFWEEK(dateStr)].substring(0, 3); },
"%%": function(){ return "%"; } // Allow for literal "%Y" using "%%Y"
//"%": "" // Not reliable, because Object.keys() does not guarantee order
};
var exp = new RegExp(dateMapRegExp, "gi");

View File

@ -906,13 +906,13 @@ function ahuacatlDateFunctionsTestSuite () {
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD({}, 1, 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), 1, 'sugar')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), 1, '')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), '', 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), '1', 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), 'one', 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), null, 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), false, 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), [], 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_INVALID_DATE_VALUE.code, "RETURN DATE_ADD(DATE_NOW(), {}, 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), '', 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), '1', 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), 'one', 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), null, 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), false, 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), [], 'year')");
assertQueryWarningAndNull(errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH.code, "RETURN DATE_ADD(DATE_NOW(), {}, 'year')");
},
////////////////////////////////////////////////////////////////////////////////
@ -940,7 +940,7 @@ function ahuacatlDateFunctionsTestSuite () {
[ ["2012-02-12 23:59:59.991", 9, "f"], "2012-02-13T00:00:00.000Z" ],
[ ["2012-02-12 23:59:59.991Z", 9, "ms"], "2012-02-13T00:00:00.000Z" ],
[ ["2012-02-12 23:59:59.991Z", "PT0.009S"], "2012-02-13T00:00:00.000Z" ],
[ ["2012-02-12", "p1y"], "2020-02-12T00:00:00.000Z" ], /* lower-case ISO durations currently allowed */
[ ["2012-02-12", "p1y"], "2013-02-12T00:00:00.000Z" ], /* lower-case ISO durations currently allowed */
[ ["2012-02-12", 8, "years"], "2020-02-12T00:00:00.000Z" ],
[ ["2012-02-12Z", 8, "year"], "2020-02-12T00:00:00.000Z" ],
[ ["2012-02-12T13:24:12Z", 8, "y"], "2020-02-12T13:24:12.000Z" ],
@ -957,8 +957,8 @@ function ahuacatlDateFunctionsTestSuite () {
[ ["2015-02-22Z", 1, "weeks"], "2015-03-01T00:00:00.000Z" ],
[ ["2015-02-22Z", 1, "week"], "2015-03-01T00:00:00.000Z" ],
[ ["2015-02-22Z", "P1W"], "2015-03-01T00:00:00.000Z" ],
[ ["2016-02-22Z", 1, "week"], "2015-02-29T00:00:00.000Z" ],
[ ["2016-02-22Z", "P1W"], "2015-02-29T00:00:00.000Z" ],
[ ["2016-02-22Z", 1, "week"], "2016-02-29T00:00:00.000Z" ],
[ ["2016-02-22Z", "P1W"], "2016-02-29T00:00:00.000Z" ],
[ ["1221-02-28T23:59:59Z", 800*12, "months"], "2021-02-28T23:59:59.000Z" ],
[ ["1221-02-28 23:59:59Z", 800, "years"], "2021-02-28T23:59:59.000Z" ],
[ ["1221-02-28Z", 1000*(60*60*24-1), "ms"], "1221-02-28T23:59:59.000Z" ],
@ -990,11 +990,20 @@ function ahuacatlDateFunctionsTestSuite () {
];
values.forEach(function (value) {
var actual = getQueryResults("RETURN DATE_ADD(@value, @amount, @unit)", {
value: value[0][0],
amount: value[0][1],
unit: value[0][2],
});
var actual;
if (value[0][2] === undefined) {
actual = getQueryResults("RETURN DATE_ADD(@value, @amount)", {
value: value[0][0],
amount: value[0][1]
});
}
else {
actual = getQueryResults("RETURN DATE_ADD(@value, @amount, @unit)", {
value: value[0][0],
amount: value[0][1],
unit: value[0][2],
});
}
assertEqual([ value[1] ], actual);
});
},