xsharp.eu • Xbase date to Nullable<DateTime>
Page 1 of 1

Xbase date to Nullable<DateTime>

Posted: Fri Sep 27, 2019 9:14 am
by wriedmann
Hello,

IMHO a conversion from a null_date to Nullable<DateTime> should result in a null value, and not in a DateTime.MinValue.
This code

Code: Select all

local dDate as date
local dResult as DateTime
local dResultN as Nullable<DateTime>

dDate := null_date
dResult := dDate
dResultN := dDate
System.Console.WriteLine( String.Format( "{0} gives {1} (DateTime) and {2} (Nullable<DateTime>)", dDate:ToString(), dResult:ToString(), dResultN:ToString() ) )
gives the following output:

Code: Select all

  .  .     gives 01.01.0001 00:00:00 (DateTime) and 01.01.0001 00:00:00 (Nullable<DateTime>)
Wolfgang

Xbase date to Nullable<DateTime>

Posted: Fri Sep 27, 2019 10:06 am
by robert
Wolfgang,
Yes I understand why you expect that.

I think that under the hood this is translated to
- convert the NULL_DATE -> DateTime
- assign the Datetime to the Nullable<DateTime>
In the first step the DateTime gets set to DateTime.Minvalue because there no representation of a NULL_DATE in the DateTime type.

Robert

Xbase date to Nullable<DateTime>

Posted: Fri Sep 27, 2019 10:12 am
by wriedmann
Hi Robert,
in the meantime I can add a workaround in my framework class like that:

Code: Select all

virtual method FieldGetNullableDateTime( cFieldName as string ) as Nullable<DateTime>
local dValue as Nullable<DateTime>
local dDate as date

dDate := ( date ) super:FieldGet( cFieldName )
if dDate == null_date
  dValue := null
else
  dValue := dDate
endif

return dValue
If you think that the actual behavior should be changed, I can add a ticket. I have preferred to ask before I do that.

Wolfgang