From 722f3121b268603c8168103613f4ab74539d6e51 Mon Sep 17 00:00:00 2001 From: DimitryOrlov Date: Thu, 28 Sep 2023 14:16:12 +0400 Subject: [PATCH] [se] Fix/year function (#3808) * [se] Update YEAR function. Added tests for YEAR and MONTH --- .../FormulaObjects/dateandtimeFunctions.js | 45 +- .../spreadsheet-calculation/FormulaTests.js | 491 ++++++++++++++++++ 2 files changed, 512 insertions(+), 24 deletions(-) diff --git a/cell/model/FormulaObjects/dateandtimeFunctions.js b/cell/model/FormulaObjects/dateandtimeFunctions.js index b97f77bb64..c8ac8282cf 100644 --- a/cell/model/FormulaObjects/dateandtimeFunctions.js +++ b/cell/model/FormulaObjects/dateandtimeFunctions.js @@ -2232,31 +2232,25 @@ cYEAR.prototype.numFormat = AscCommonExcel.cNumFormatNone; cYEAR.prototype.argumentsType = [argType.number]; cYEAR.prototype.Calculate = function (arg) { - var t = this; - var bIsSpecialFunction = arguments[4]; - - var calculateFunc = function(curArg) { - var val; + let t = this; + let bIsSpecialFunction = arguments[4]; - if (curArg instanceof cError) { + let calculateFunc = function(curArg) { + let val; + if (curArg.type === cElementType.cell || curArg.type === cElementType.cell3D) { + curArg = curArg.getValue(); + } + + if (curArg.type === cElementType.error) { return curArg; - } else if (curArg instanceof cNumber || curArg instanceof cBool || curArg instanceof cEmpty) { + } else if (curArg.type === cElementType.number || curArg.type === cElementType.bool || curArg.type === cElementType.empty) { val = curArg.tocNumber().getValue(); - } else if (curArg instanceof cArea || curArg instanceof cArea3D) { + } else if (curArg.type === cElementType.cellsRange || curArg.type === cElementType.cellsRange3D) { return new cError(cErrorType.wrong_value_type); - } else if (curArg instanceof cRef || curArg instanceof cRef3D) { - val = curArg.getValue(); - if (val instanceof cError) { - return val; - } else if (val instanceof cNumber || val instanceof cBool || val instanceof cEmpty) { - val = curArg.tocNumber().getValue(); - } else { - return new cError(cErrorType.wrong_value_type); - } - } else if (curArg instanceof cString) { + } else if (curArg.type === cElementType.string) { val = curArg.tocNumber(); - if (val instanceof cError || val instanceof cEmpty) { - var d = new cDate(curArg.getValue()); + if (val.type === cElementType.error || val.type === cElementType.empty) { + let d = new cDate(curArg.getValue()); if (isNaN(d)) { return new cError(cErrorType.wrong_value_type); } else { @@ -2266,19 +2260,22 @@ val = curArg.tocNumber().getValue(); } } + if (val < 0) { return t.setCalcValue(new cError(cErrorType.not_numeric), 0); } else { + if (AscCommon.bDate1904 && val === 0) { + val += 1; + } return t.setCalcValue(new cNumber((new cDate((val - (AscCommonExcel.c_DateCorrectConst + 1)) * c_msPerDay)).getUTCFullYear()), 0); } }; - var arg0 = arg[0], res; + let arg0 = arg[0], res; if(!bIsSpecialFunction) { - - if (arg0 instanceof cArray) { + if (arg0.type === cElementType.array) { arg0 = arg0.getElement(0); - } else if (arg0 instanceof cArea || arg0 instanceof cArea3D) { + } else if (arg0.type === cElementType.cellsRange || arg0.type === cElementType.cellsRange3D) { arg0 = arg0.cross(arguments[1]).tocNumber(); } res = calculateFunc(arg0); diff --git a/tests/cell/spreadsheet-calculation/FormulaTests.js b/tests/cell/spreadsheet-calculation/FormulaTests.js index 3b6656d307..bdeecd21f9 100644 --- a/tests/cell/spreadsheet-calculation/FormulaTests.js +++ b/tests/cell/spreadsheet-calculation/FormulaTests.js @@ -5151,6 +5151,497 @@ $(function () { testArrayFormula2(assert, "EOMONTH", 2, 2, true, null); }); + QUnit.test("Test: \"MONTH\"", function (assert) { + ws.getRange2("A1:A15").cleanAll(); + + // base mode + ws.workbook.setDate1904(false, true); + + // inline + oParser = new parserFormula("MONTH(44469)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(30.09.21)"); + assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH(30.09.21)"); + + oParser = new parserFormula("MONTH(44560)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(30.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(30.12.21)"); + + oParser = new parserFormula("MONTH(44561)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(31.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(31.12.21)"); + + oParser = new parserFormula("MONTH(44510)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(10.11.21)"); + assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH(10.11.21)"); + + oParser = new parserFormula('MONTH("2021-10-01")', "A2", ws); + assert.ok(oParser.parse(), 'MONTH("2021-10-01")'); + assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of MONTH("2021-10-01")'); + + oParser = new parserFormula('MONTH("2021-12-31")', "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-12-31')"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-31')"); + + oParser = new parserFormula('MONTH("2021-09-30")', "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-09-30')"); + assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH('2021-09-30')"); + + oParser = new parserFormula('MONTH("2021-10-31")', "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-10-31')"); + assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-31')"); + + oParser = new parserFormula('MONTH("2021-12-29")', "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-12-29')"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-29')"); + + oParser = new parserFormula('MONTH(0)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(0)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(0)"); + + oParser = new parserFormula('MONTH("1s")', "A2", ws); + assert.ok(oParser.parse(), "MONTH('1s')"); + assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MONTH('1s')"); + + oParser = new parserFormula('MONTH(TRUE)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(TRUE)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(TRUE)"); + + oParser = new parserFormula('MONTH(FALSE)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(FALSE)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(FALSE)"); + + oParser = new parserFormula('MONTH(#DIV/0!)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(#DIV/0!)"); + assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of MONTH(#DIV/0!)"); + + // cell + ws.getRange2("A1").setValue("44469"); + ws.getRange2("A2").setValue("44560"); + ws.getRange2("A3").setValue("44561"); + ws.getRange2("A4").setValue("44510"); + ws.getRange2("A5").setValue("2021-10-01"); + ws.getRange2("A6").setValue("2021-12-31"); + ws.getRange2("A7").setValue("2021-09-30"); + ws.getRange2("A8").setValue("2021-10-31"); + ws.getRange2("A9").setValue("2021-12-29"); + + ws.getRange2("A10").setValue("0"); + ws.getRange2("A11").setValue("1s"); + ws.getRange2("A12").setValue("TRUE"); + ws.getRange2("A13").setValue("FALSE"); + ws.getRange2("A14").setValue("#DIV/0!"); + ws.getRange2("A15").setValue(""); + + oParser = new parserFormula("MONTH(A1)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(30.09.21)"); + assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH(30.09.21)"); + + oParser = new parserFormula("MONTH(A2)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(30.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(30.12.21)"); + + oParser = new parserFormula("MONTH(A3)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(31.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(31.12.21)"); + + oParser = new parserFormula("MONTH(A4)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(10.11.21)"); + assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH(10.11.21)"); + + oParser = new parserFormula("MONTH(A5)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-10-01')"); + assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-01')"); + + oParser = new parserFormula("MONTH(A6)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-12-31')"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-31')"); + + oParser = new parserFormula("MONTH(A7)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-09-30')"); + assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH('2021-09-30')"); + + oParser = new parserFormula("MONTH(A8)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-10-31')"); + assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-31')"); + + oParser = new parserFormula("MONTH(A9)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-12-29')"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-29')"); + + oParser = new parserFormula('MONTH(A10)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(0)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(0)"); + + oParser = new parserFormula('MONTH(A11)', "A2", ws); + assert.ok(oParser.parse(), "MONTH('1s')"); + assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MONTH('1s')"); + + oParser = new parserFormula('MONTH(A12)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(TRUE)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(TRUE)"); + + oParser = new parserFormula('MONTH(A13)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(FALSE)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(FALSE)"); + + oParser = new parserFormula('MONTH(A14)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(#DIV/0!)"); + assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of MONTH(#DIV/0!)"); + + oParser = new parserFormula('MONTH(A15)', "A2", ws); + assert.ok(oParser.parse(), "MONTH('')"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH('')"); + + oParser = new parserFormula('MONTH(A1:A4)', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("C1:C5").bbox); + assert.ok(oParser.parse(), "MONTH(A1:A4)"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, "Result of MONTH(A1:A4)[0,0]"); + assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 12, "Result of MONTH(A1:A4)[1,0]"); + assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 12, "Result of MONTH(A1:A4)[2,0]"); + assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 11, "Result of MONTH(A1:A4)[3,0]"); + assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of MONTH(A1:A4)[4,0]"); + + oParser = new parserFormula('MONTH({1,100,1000,10000})', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); + assert.ok(oParser.parse(), "MONTH({1,100,1000,10000})"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of MONTH({1,100,1000,10000})[0,0]"); + assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of MONTH({1,100,1000,10000})[0,1]"); + assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 9, "Result of MONTH({1,100,1000,10000})[0,2]"); + assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 5, "Result of MONTH({1,100,1000,10000})[0,3]"); + assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of MONTH({1,100,1000,10000})[0,4]"); + + // set 1904 mode + ws.workbook.setDate1904(true, true); + + oParser = new parserFormula("MONTH(A1)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(30.09.21)"); + assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH(30.09.21)"); + + oParser = new parserFormula("MONTH(A2)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(30.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(30.12.21)"); + + oParser = new parserFormula("MONTH(A3)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(31.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(31.12.21)"); + + oParser = new parserFormula("MONTH(A4)", "A2", ws); + assert.ok(oParser.parse(), "MONTH(10.11.21)"); + assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH(10.11.21)"); + + oParser = new parserFormula("MONTH(A5)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-10-01')"); + assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-01')"); + + oParser = new parserFormula("MONTH(A6)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-12-31')"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH('2021-12-31')"); + + oParser = new parserFormula("MONTH(A7)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-09-30')"); + assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-09-30')"); + + oParser = new parserFormula("MONTH(A8)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-10-31')"); + assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH('2021-10-31')"); + + oParser = new parserFormula("MONTH(A9)", "A2", ws); + assert.ok(oParser.parse(), "MONTH('2021-12-29')"); + assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-29')"); + + oParser = new parserFormula('MONTH(A10)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(0)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(0)"); + + oParser = new parserFormula('MONTH(A11)', "A2", ws); + assert.ok(oParser.parse(), "MONTH('1s')"); + assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MONTH('1s')"); + + oParser = new parserFormula('MONTH(A12)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(TRUE)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(TRUE)"); + + oParser = new parserFormula('MONTH(A13)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(FALSE)"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(FALSE)"); + + oParser = new parserFormula('MONTH(A14)', "A2", ws); + assert.ok(oParser.parse(), "MONTH(#DIV/0!)"); + assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of MONTH(#DIV/0!)"); + + oParser = new parserFormula('MONTH(A15)', "A2", ws); + assert.ok(oParser.parse(), "MONTH('')"); + assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH('')"); + + oParser = new parserFormula('MONTH(A1:A4)', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("C1:C5").bbox); + assert.ok(oParser.parse(), "MONTH(A1:A4)"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 10, "Result of MONTH(A1:A4)[0,0]"); + assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 12, "Result of MONTH(A1:A4)[1,0]"); + assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of MONTH(A1:A4)[2,0]"); + assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 11, "Result of MONTH(A1:A4)[3,0]"); + assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of MONTH(A1:A4)[4,0]"); + + oParser = new parserFormula('MONTH({1,100,1000,10000})', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); + assert.ok(oParser.parse(), "MONTH({1,100,1000,10000})"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of MONTH({1,100,1000,10000})[0,0]"); + assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of MONTH({1,100,1000,10000})[0,1]"); + assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 9, "Result of MONTH({1,100,1000,10000})[0,2]"); + assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 5, "Result of MONTH({1,100,1000,10000})[0,3]"); + assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of MONTH({1,100,1000,10000})[0,4]"); + + // return to base mode + ws.workbook.setDate1904(false, true); + + testArrayFormula2(assert, "MONTH"); + }); + + QUnit.test("Test: \"YEAR\"", function (assert) { + let array; + ws.getRange2("A1:A15").cleanAll(); + + // base mode + ws.workbook.setDate1904(false, true); + + // inline + oParser = new parserFormula("YEAR(44469)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(30.09.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.09.21)"); + + oParser = new parserFormula("YEAR(44560)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(30.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.12.21)"); + + oParser = new parserFormula("YEAR(44561)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(31.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(31.12.21)"); + + oParser = new parserFormula("YEAR(44510)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(10.11.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(10.11.21)"); + + oParser = new parserFormula('YEAR("2021-10-01")', "A2", ws); + assert.ok(oParser.parse(), 'YEAR("2021-10-01")'); + assert.strictEqual(oParser.calculate().getValue(), 2021, 'Result of YEAR("2021-10-01")'); + + oParser = new parserFormula('YEAR("2021-12-31")', "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-12-31')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-31')"); + + oParser = new parserFormula('YEAR("2021-09-30")', "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-09-30')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-09-30')"); + + oParser = new parserFormula('YEAR("2021-10-31")', "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-10-31')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-10-31')"); + + oParser = new parserFormula('YEAR("2021-12-29")', "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-12-29')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-29')"); + + oParser = new parserFormula('YEAR(0)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(0)"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(0)"); + + oParser = new parserFormula('YEAR("1s")', "A2", ws); + assert.ok(oParser.parse(), "YEAR('1s')"); + assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of YEAR('1s')"); + + oParser = new parserFormula('YEAR(TRUE)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(TRUE)"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(TRUE)"); + + oParser = new parserFormula('YEAR(FALSE)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(FALSE)"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(FALSE)"); + + oParser = new parserFormula('YEAR(#DIV/0!)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(#DIV/0!)"); + assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of YEAR(#DIV/0!)"); + + // cell + ws.getRange2("A1").setValue("44469"); + ws.getRange2("A2").setValue("44560"); + ws.getRange2("A3").setValue("44561"); + ws.getRange2("A4").setValue("44510"); + ws.getRange2("A5").setValue("2021-10-01"); + ws.getRange2("A6").setValue("2021-12-31"); + ws.getRange2("A7").setValue("2021-09-30"); + ws.getRange2("A8").setValue("2021-10-31"); + ws.getRange2("A9").setValue("2021-12-29"); + + ws.getRange2("A10").setValue("0"); + ws.getRange2("A11").setValue("1s"); + ws.getRange2("A12").setValue("TRUE"); + ws.getRange2("A13").setValue("FALSE"); + ws.getRange2("A14").setValue("#DIV/0!"); + ws.getRange2("A15").setValue(""); + + oParser = new parserFormula("YEAR(A1)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(30.09.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.09.21)"); + + oParser = new parserFormula("YEAR(A2)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(30.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.12.21)"); + + oParser = new parserFormula("YEAR(A3)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(31.12.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(31.12.21)"); + + oParser = new parserFormula("YEAR(A4)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(10.11.21)"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(10.11.21)"); + + oParser = new parserFormula("YEAR(A5)", "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-10-01')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-10-01')"); + + oParser = new parserFormula("YEAR(A6)", "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-12-31')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-31')"); + + oParser = new parserFormula("YEAR(A7)", "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-09-30')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-09-30')"); + + oParser = new parserFormula("YEAR(A8)", "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-10-31')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-10-31')"); + + oParser = new parserFormula("YEAR(A9)", "A2", ws); + assert.ok(oParser.parse(), "YEAR('2021-12-29')"); + assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-29')"); + + oParser = new parserFormula('YEAR(A10)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(0)"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(0)"); + + oParser = new parserFormula('YEAR(A11)', "A2", ws); + assert.ok(oParser.parse(), "YEAR('1s')"); + assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of YEAR('1s')"); + + oParser = new parserFormula('YEAR(A12)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(TRUE)"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(TRUE)"); + + oParser = new parserFormula('YEAR(A13)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(FALSE)"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(FALSE)"); + + oParser = new parserFormula('YEAR(A14)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(#DIV/0!)"); + assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of YEAR(#DIV/0!)"); + + oParser = new parserFormula('YEAR(A15)', "A2", ws); + assert.ok(oParser.parse(), "YEAR('')"); + assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR('')"); + + oParser = new parserFormula('YEAR(A1:A4)', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("C1:C5").bbox); + assert.ok(oParser.parse(), "YEAR(A1:A4)"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2021, "Result of YEAR(A1:A4)[0,0]"); + assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2021, "Result of YEAR(A1:A4)[1,0]"); + assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2021, "Result of YEAR(A1:A4)[2,0]"); + assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 2021, "Result of YEAR(A1:A4)[3,0]"); + assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of YEAR(A1:A4)[4,0]"); + + oParser = new parserFormula('YEAR({1,100,1000,10000})', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); + assert.ok(oParser.parse(), "YEAR({1,100,1000,10000})"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1900, "Result of YEAR({1,100,1000,10000})[0,0]"); + assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1900, "Result of YEAR({1,100,1000,10000})[0,1]"); + assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1902, "Result of YEAR({1,100,1000,10000})[0,2]"); + assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1927, "Result of YEAR({1,100,1000,10000})[0,3]"); + assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of YEAR({1,100,1000,10000})[0,4]"); + + // set 1904 mode + ws.workbook.setDate1904(true, true); + + oParser = new parserFormula("YEAR(A1)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A1)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A1)"); + + oParser = new parserFormula("YEAR(A2)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A2)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A2)"); + + oParser = new parserFormula("YEAR(A3)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A3)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A3)"); + + oParser = new parserFormula("YEAR(A4)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A4)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A4)"); + + oParser = new parserFormula("YEAR(A5)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A5)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A5)"); + + oParser = new parserFormula("YEAR(A6)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A6)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A6)"); + + oParser = new parserFormula("YEAR(A7)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A7)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A7)"); + + oParser = new parserFormula("YEAR(A8)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A8)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A8)"); + + oParser = new parserFormula("YEAR(A9)", "A2", ws); + assert.ok(oParser.parse(), "YEAR(A9)"); + assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A9)"); + + oParser = new parserFormula('YEAR(A10)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(A10)"); + assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A10)"); + + oParser = new parserFormula('YEAR(A11)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(A11)"); + assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of YEAR(A11)"); + + oParser = new parserFormula('YEAR(A12)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(A12)"); + assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A12)"); + + oParser = new parserFormula('YEAR(A13)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(A13)"); + assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A13)"); + + oParser = new parserFormula('YEAR(A14)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(A14)"); + assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of YEAR(A14)"); + + oParser = new parserFormula('YEAR(A15)', "A2", ws); + assert.ok(oParser.parse(), "YEAR(A15)"); + assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A15)"); + + oParser = new parserFormula('YEAR({1,100,1000,10000})', "A2", ws); + oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); + assert.ok(oParser.parse(), "YEAR({1,100,1000,10000})"); + array = oParser.calculate(); + assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1904, "Result of YEAR({1,100,1000,10000})[0,0]"); + assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1904, "Result of YEAR({1,100,1000,10000})[0,1]"); + assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1906, "Result of YEAR({1,100,1000,10000})[0,2]"); + assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1931, "Result of YEAR({1,100,1000,10000})[0,3]"); + assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of YEAR({1,100,1000,10000})[0,4]"); + + // return to base mode + ws.workbook.setDate1904(false, true); + + testArrayFormula2(assert, "YEAR"); + }); + QUnit.test("Test: \"EVEN\"", function (assert) { oParser = new parserFormula("EVEN(1.5)", "A2", ws);