Xbase date to Nullable<DateTime>

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Xbase date to Nullable<DateTime>

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Xbase date to Nullable<DateTime>

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Xbase date to Nullable<DateTime>

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply