Skip to content

Commit

Permalink
Ignores time differences in Date and date differences in Time #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 6, 2024
1 parent 6889b1b commit 4d8f323
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions Source/BoldAttributes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,10 @@ TBAMoment = class(TBANumeric)
function GetAsDate: TDateTime;
function GetAsDateTime: TDateTime;
function GetAsTime: TDateTime;
procedure SetAsDate(Value: TDateTime);
procedure SetAsDate(Value: TDateTime); virtual; abstract;
procedure SetAsDateTime(Value: TDateTime);
procedure SetAsTime(Value: TDateTime);
function IsSameValue(Value: TDateTime): boolean; virtual; abstract;
function MaySetValue(NewValue: TDateTime; Subscriber: TBoldSubscriber): Boolean; virtual;
property AsDate: TDateTime read GetAsDate write SetAsDate;
property AsTime: TDateTime read GetAsTime write SetAsTime;
Expand Down Expand Up @@ -566,6 +567,8 @@ TBADateTime = class(TBAMoment)
class procedure ClearAttributeTypeInfo;
protected
function GetAttributeTypeInfoForType: TBoldElementTypeInfo; override;
function IsSameValue(Value: TDateTime): boolean; override;
procedure SetAsDate(Value: TDateTime); override;
procedure AssignContentValue(const Source: IBoldValue); override;
function GetStringRepresentation(Representation: TBoldRepresentation): string; override;
procedure SetStringRepresentation(Representation: TBoldRepresentation; const Value: string); override;
Expand Down Expand Up @@ -596,6 +599,8 @@ TBADate = class(TBAMoment)
class procedure ClearAttributeTypeInfo;
protected
function GetAttributeTypeInfoForType: TBoldElementTypeInfo; override;
procedure SetAsDate(Value: TDateTime); override;
function IsSameValue(Value: TDateTime): boolean; override;
procedure AssignContentValue(const Source: IBoldValue); override;
procedure SetStringRepresentation(Representation: TBoldRepresentation; const Value: string); override;
function GetStringRepresentation(Representation: TBoldRepresentation): string; override;
Expand Down Expand Up @@ -623,6 +628,8 @@ TBATime = class(TBAMoment)
function GetAsSeconds: cardinal;
protected
function GetAttributeTypeInfoForType: TBoldElementTypeInfo; override;
procedure SetAsDate(Value: TDateTime); override;
function IsSameValue(Value: TDateTime): boolean; override;
procedure AssignContentValue(const Source: IBoldValue); override;
procedure SetStringRepresentation(Representation: TBoldRepresentation; const Value: string); override;
function GetStringRepresentation(Representation: TBoldRepresentation): string; override;
Expand Down Expand Up @@ -1043,7 +1050,7 @@ function TBAString.ValidateString(const Value: string; Representation: TBoldRepr
end
else
Result := True;
end;
end;

procedure TBAString.Assign(Source: TBoldElement);
begin
Expand Down Expand Up @@ -3450,7 +3457,7 @@ procedure TBAMoment.SetDataValue(NewValue: TDateTime);
bContentIsNull: Boolean;
sOldValue: TDateTime;
begin
if IsNull or (FValue <> NewValue) then
if IsNull or not IsSameValue(NewValue) then
begin
BoldClearLastFailure;
{$IFDEF NoNegativeDates}
Expand Down Expand Up @@ -3542,14 +3549,6 @@ procedure TBAMoment.SetAsInteger(Value: integer);
SetAsDate(Value);
end;

procedure TBAMoment.SetAsDate(Value: TDateTime);
begin
if IsNull then
SetAsDateTime(Int(Value))
else
SetAsDateTime(Int(Value) + AsTime);
end;

procedure TBAMoment.SetAsTime(Value: TDateTime);
begin
if IsNull then
Expand Down Expand Up @@ -4197,6 +4196,16 @@ function TBADateTime.ProxyInterface(const IId: TGUID; Mode: TBoldDomainElementPr
result := inherited ProxyInterface(IID, Mode, Obj);
end;

procedure TBADateTime.SetAsDate(Value: TDateTime);
begin
SetDataValue(Value);
end;

function TBADateTime.IsSameValue(Value: TDateTime): boolean;
begin
result := SameValue(Value, fValue);
end;

function TBADateTime.GetAttributeTypeInfoForType: TBoldElementTypeInfo;
begin
if not Assigned(AttributeTypeInfo) then
Expand Down Expand Up @@ -5244,6 +5253,16 @@ function TBATime.ProxyInterface(const IId: TGUID; Mode: TBoldDomainElementProxyM
result := inherited ProxyInterface(IId, Mode, Obj);
end;

procedure TBADate.SetAsDate(Value: TDateTime);
begin
SetDataValue(Trunc(Value));
end;

function TBADate.IsSameValue(Value: TDateTime): boolean;
begin
result := Trunc(Value) = fValue;
end;

function TBADate.GetAttributeTypeInfoForType: TBoldElementTypeInfo;
begin
if not Assigned(AttributeTypeInfo) then
Expand Down Expand Up @@ -5305,6 +5324,16 @@ function TBATime.GetAsSeconds: cardinal;
Result := Seconds + (Minutes * 60) + (Hours * 3600);
end;

procedure TBATime.SetAsDate(Value: TDateTime);
begin
SetDataValue(Frac(Value));
end;

function TBATime.IsSameValue(Value: TDateTime): boolean;
begin
result := SameValue(Frac(Value), fValue);
end;

function TBATime.GetAttributeTypeInfoForType: TBoldElementTypeInfo;
begin
if not Assigned(AttributeTypeInfo) then
Expand Down

0 comments on commit 4d8f323

Please sign in to comment.