Commit c1bc97fd authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix DATEVALUE function calculate (examples:

=DATEVALUE(2016) we calc to 2016 value. Can be #VALUE!;

cell A7 enter value: 3-Mar
other cell value:  =DATEVALUE(A7)
if A7 format as text  -> 42432, or if General can be #VALUE!;
)

fix unit tests for DATEVALUE
delete unused regexp variables
parent 84d3d164
...@@ -389,7 +389,7 @@ $( function () { ...@@ -389,7 +389,7 @@ $( function () {
var oParser, wb, ws, dif = 1e-9, var oParser, wb, ws, dif = 1e-9,
data = getTestWorkbook(), data = getTestWorkbook(),
sData = data + ""; sData = data + "", tmp;
if ( AscCommon.c_oSerFormat.Signature === sData.substring( 0, AscCommon.c_oSerFormat.Signature.length ) ) { if ( AscCommon.c_oSerFormat.Signature === sData.substring( 0, AscCommon.c_oSerFormat.Signature.length ) ) {
var sUrlPath = "offlinedocs/"; var sUrlPath = "offlinedocs/";
wb = new AscCommonExcel.Workbook( new AscCommonExcel.asc_CHandlersList(), {wb:{getWorksheet:function(){}}} ); wb = new AscCommonExcel.Workbook( new AscCommonExcel.asc_CHandlersList(), {wb:{getWorksheet:function(){}}} );
...@@ -1043,7 +1043,9 @@ $( function () { ...@@ -1043,7 +1043,9 @@ $( function () {
ok( oParser.parse() ); ok( oParser.parse() );
strictEqual( oParser.calculate().getValue(), 40461 ); strictEqual( oParser.calculate().getValue(), 40461 );
ws.getRange2( "A7" ).setValue( "3-Mar" ); tmp = ws.getRange2( "A7" );
tmp.setNumFormat('@');
tmp.setValue( "3-Mar" );
oParser = new parserFormula( "DATEVALUE(A7)", "A2", ws ); oParser = new parserFormula( "DATEVALUE(A7)", "A2", ws );
ok( oParser.parse() ); ok( oParser.parse() );
var d = new Date(); var d = new Date();
......
...@@ -519,11 +519,7 @@ cDATEVALUE.prototype.Calculate = function ( arg ) { ...@@ -519,11 +519,7 @@ cDATEVALUE.prototype.Calculate = function ( arg ) {
if ( arg0 instanceof cError ) if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
if ( arg0.tocNumber() instanceof cNumber && arg0.tocNumber().getValue() > 0 )
return this.value = new cNumber( parseInt( arg0.tocNumber().getValue() ) );
var res = g_oFormatParser.parse( arg0.getValue() ); var res = g_oFormatParser.parse( arg0.getValue() );
if ( res && res.bDateTime ) if ( res && res.bDateTime )
return this.value = new cNumber( parseInt( res.value ) ); return this.value = new cNumber( parseInt( res.value ) );
else else
...@@ -1200,19 +1196,19 @@ function cNOW() { ...@@ -1200,19 +1196,19 @@ function cNOW() {
} }
cNOW.prototype = Object.create( cBaseFunction.prototype ) cNOW.prototype = Object.create( cBaseFunction.prototype );
cNOW.prototype.Calculate = function () { cNOW.prototype.Calculate = function () {
var d = new Date(); var d = new Date();
this.value = new cNumber( d.getExcelDate() + (d.getUTCHours() * 60 * 60 + d.getUTCMinutes() * 60 + d.getUTCSeconds()) / c_sPerDay ); this.value = new cNumber( d.getExcelDate() + (d.getUTCHours() * 60 * 60 + d.getUTCMinutes() * 60 + d.getUTCSeconds()) / c_sPerDay );
this.value.numFormat = 22; this.value.numFormat = 22;
return this.setCA( this.value, true ); return this.setCA( this.value, true );
} };
cNOW.prototype.getInfo = function () { cNOW.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"()" args:"()"
}; };
} };
function cSECOND() { function cSECOND() {
// cBaseFunction.call( this, "SECOND", 1, 1 ); // cBaseFunction.call( this, "SECOND", 1, 1 );
...@@ -1305,7 +1301,7 @@ function cTIME() { ...@@ -1305,7 +1301,7 @@ function cTIME() {
} }
cTIME.prototype = Object.create( cBaseFunction.prototype ) cTIME.prototype = Object.create( cBaseFunction.prototype );
cTIME.prototype.Calculate = function ( arg ) { cTIME.prototype.Calculate = function ( arg ) {
var hour = arg[0], minute = arg[1], second = arg[2]; var hour = arg[0], minute = arg[1], second = arg[2];
...@@ -1345,13 +1341,13 @@ cTIME.prototype.Calculate = function ( arg ) { ...@@ -1345,13 +1341,13 @@ cTIME.prototype.Calculate = function ( arg ) {
if ( arguments[1].getNumFormatStr().toLowerCase() === "general" ) if ( arguments[1].getNumFormatStr().toLowerCase() === "general" )
this.value.numFormat = 18; this.value.numFormat = 18;
return this.value; return this.value;
} };
cTIME.prototype.getInfo = function () { cTIME.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
args:"( hour, minute, second )" args:"( hour, minute, second )"
}; };
} };
function cTIMEVALUE() { function cTIMEVALUE() {
// cBaseFunction.call( this, "TIMEVALUE", 1, 1 ); // cBaseFunction.call( this, "TIMEVALUE", 1, 1 );
...@@ -1371,7 +1367,7 @@ function cTIMEVALUE() { ...@@ -1371,7 +1367,7 @@ function cTIMEVALUE() {
} }
cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype ) cTIMEVALUE.prototype = Object.create( cBaseFunction.prototype );
cTIMEVALUE.prototype.Calculate = function ( arg ) { cTIMEVALUE.prototype.Calculate = function ( arg ) {
var arg0 = arg[0]; var arg0 = arg[0];
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment