microsoft / Power-Fx

Power Fx low-code programming language
MIT License
3.21k stars 327 forks source link

Negate of Date/DateTime/Time results in null reference exception #1176

Closed gregli-msft closed 1 year ago

gregli-msft commented 1 year ago

-Date(1900,1,1) -Time(12,0,0) -DateTime(1900,1,1,12,0,0)

Results in this exception, where Args has a null, as the Date value was filtered out in argument preprocessing: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.PowerFx.Functions.Library.NumericNegate(IRContext irContext, NumberValue[] args)

In Excel, these display as ###... but the underlying number is there if you change the formatting (-1 and -0.5 for the first two, the DateTime function is not available in Excel). Canvas shows the first two as 12/31/2039 and 8 PM (in PST).

Excel returns a #VALUE! error for Text( -1, "yyyy-mm-dd" ), Canvas returns in a label control 1969-12-31 which appears to be using the JavaScript epoch (with or without Excel compat), and C# reutrns 1899-12-29 which appears to be using the Excel epoch.

Obviously we shouldn't have the exception and I think across the board we should be matching Excel results.

gregli-msft commented 1 year ago

@CarlosFigueiraMSFT , I thought you might want to take a look at this, as it is an Excel compat question.