You've already forked lazarus-ccr
TTDurationRemotable and TTimeRemotable and TDateRemotable now use an uniform API :
* ToStr() * Parse() Note that this patch break compatibility a source level ( of these classes ). git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@898 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -359,7 +359,9 @@ type
|
|||||||
private
|
private
|
||||||
FDate : TDateTimeRec;
|
FDate : TDateTimeRec;
|
||||||
private
|
private
|
||||||
|
function GetAsString: string;
|
||||||
function GetOffset(const Index: Integer): Shortint;
|
function GetOffset(const Index: Integer): Shortint;
|
||||||
|
procedure SetAsString(const AValue: string);
|
||||||
procedure SetOffset(const Index: Integer; const Value: Shortint);
|
procedure SetOffset(const Index: Integer; const Value: Shortint);
|
||||||
function GetDate(const AIndex : Integer) : TDateTime;
|
function GetDate(const AIndex : Integer) : TDateTime;
|
||||||
protected
|
protected
|
||||||
@ -378,9 +380,9 @@ type
|
|||||||
var AName : string;
|
var AName : string;
|
||||||
const ATypeInfo : PTypeInfo
|
const ATypeInfo : PTypeInfo
|
||||||
);override;
|
);override;
|
||||||
class function FormatDate(const ADate : TDateTime):string;overload;
|
class function ToStr(const ADate : TDateTime):string;overload;
|
||||||
class function FormatDate(const ADate : TDateTimeRec):string;overload;virtual;abstract;
|
class function ToStr(const ADate : TDateTimeRec):string;overload;virtual;abstract;
|
||||||
class function ParseDate(const ABuffer : string):TDateTime;virtual;abstract;
|
class function Parse(const ABuffer : string):TDateTimeRec;virtual;abstract;
|
||||||
|
|
||||||
procedure Assign(Source: TPersistent); override;
|
procedure Assign(Source: TPersistent); override;
|
||||||
function Equal(const ACompareTo : TBaseRemotable) : Boolean;override;
|
function Equal(const ACompareTo : TBaseRemotable) : Boolean;override;
|
||||||
@ -392,6 +394,7 @@ type
|
|||||||
property Day : Integer index 2 read GetDatepart;
|
property Day : Integer index 2 read GetDatepart;
|
||||||
property HourOffset : Shortint index 0 read GetOffset write SetOffset;
|
property HourOffset : Shortint index 0 read GetOffset write SetOffset;
|
||||||
property MinuteOffset : Shortint index 1 read GetOffset write SetOffset;
|
property MinuteOffset : Shortint index 1 read GetOffset write SetOffset;
|
||||||
|
property AsString : string read GetAsString write SetAsString;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDateRemotable }
|
{ TDateRemotable }
|
||||||
@ -400,8 +403,8 @@ type
|
|||||||
protected
|
protected
|
||||||
function GetDatepart(const AIndex : Integer) : Integer;override;
|
function GetDatepart(const AIndex : Integer) : Integer;override;
|
||||||
public
|
public
|
||||||
class function FormatDate(const ADate : TDateTimeRec):string;override;
|
class function ToStr(const ADate : TDateTimeRec):string;override;
|
||||||
class function ParseDate(const ABuffer : string):TDateTime;override;
|
class function Parse(const ABuffer : string):TDateTimeRec;override;
|
||||||
property Hour : Integer index 3 read GetDatepart;
|
property Hour : Integer index 3 read GetDatepart;
|
||||||
property Minute : Integer index 4 read GetDatepart;
|
property Minute : Integer index 4 read GetDatepart;
|
||||||
property Second : Integer index 5 read GetDatepart;
|
property Second : Integer index 5 read GetDatepart;
|
||||||
@ -411,14 +414,14 @@ type
|
|||||||
|
|
||||||
TDurationRemotable = class(TAbstractSimpleRemotable)
|
TDurationRemotable = class(TAbstractSimpleRemotable)
|
||||||
private
|
private
|
||||||
FDay : PtrUInt;
|
FData : TDurationRec;
|
||||||
FFractionalSecond : PtrUInt;
|
private
|
||||||
FHour : PtrUInt;
|
function GetAsString: string;
|
||||||
FMinute : PtrUInt;
|
function GetNegative: Boolean;
|
||||||
FMonth : PtrUInt;
|
function GetPart(AIndex: integer): PtrUInt;
|
||||||
FNegative : Boolean;
|
procedure SetAsString(const AValue: string);
|
||||||
FSecond : PtrUInt;
|
procedure SetNegative(const AValue: Boolean);
|
||||||
FYear : PtrUInt;
|
procedure SetPart(AIndex: integer; const AValue: PtrUInt);
|
||||||
public
|
public
|
||||||
class procedure Save(
|
class procedure Save(
|
||||||
AObject : TBaseRemotable;
|
AObject : TBaseRemotable;
|
||||||
@ -436,17 +439,19 @@ type
|
|||||||
procedure Assign(Source: TPersistent); override;
|
procedure Assign(Source: TPersistent); override;
|
||||||
function Equal(const ACompareTo : TBaseRemotable) : Boolean;override;
|
function Equal(const ACompareTo : TBaseRemotable) : Boolean;override;
|
||||||
procedure Clear();
|
procedure Clear();
|
||||||
procedure Parse(const ABuffer : string);
|
|
||||||
function AsString() : string;
|
|
||||||
|
|
||||||
property Negative : Boolean read FNegative write FNegative;
|
class function Parse(const ABuffer : string) : TDurationRec;
|
||||||
property Year : PtrUInt read FYear write FYear;
|
class function ToStr(const AValue : TDurationRec):string;
|
||||||
property Month : PtrUInt read FMonth write FMonth;
|
|
||||||
property Day : PtrUInt read FDay write FDay;
|
property Negative : Boolean read GetNegative write SetNegative;
|
||||||
property Hour : PtrUInt read FHour write FHour;
|
property Year : PtrUInt index 0 read GetPart write SetPart;
|
||||||
property Minute : PtrUInt read FMinute write FMinute;
|
property Month : PtrUInt index 1 read GetPart write SetPart;
|
||||||
property Second : PtrUInt read FSecond write FSecond;
|
property Day : PtrUInt index 2 read GetPart write SetPart;
|
||||||
property FractionalSecond : PtrUInt read FFractionalSecond write FFractionalSecond;
|
property Hour : PtrUInt index 3 read GetPart write SetPart;
|
||||||
|
property Minute : PtrUInt index 4 read GetPart write SetPart;
|
||||||
|
property Second : PtrUInt index 5 read GetPart write SetPart;
|
||||||
|
property FractionalSecond : PtrUInt index 6 read GetPart write SetPart;
|
||||||
|
property AsString : string read GetAsString write SetAsString;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTimeRemotable }
|
{ TTimeRemotable }
|
||||||
@ -482,7 +487,7 @@ type
|
|||||||
procedure Clear();
|
procedure Clear();
|
||||||
|
|
||||||
class function Parse(const ABuffer : string) : TTimeRec;
|
class function Parse(const ABuffer : string) : TTimeRec;
|
||||||
class function ToString(const AValue : TTimeRec) : string;
|
class function ToStr(const AValue : TTimeRec) : string;
|
||||||
|
|
||||||
property Hour : Byte index 0 read GetPart write SetPart;
|
property Hour : Byte index 0 read GetPart write SetPart;
|
||||||
property Minute : Byte index 1 read GetPart write SetPart;
|
property Minute : Byte index 1 read GetPart write SetPart;
|
||||||
@ -3569,9 +3574,9 @@ begin
|
|||||||
Assert(AObject.InheritsFrom(TObjectCollectionRemotable));
|
Assert(AObject.InheritsFrom(TObjectCollectionRemotable));
|
||||||
nativObj := AObject as TObjectCollectionRemotable;
|
nativObj := AObject as TObjectCollectionRemotable;
|
||||||
styl := GetStyle();
|
styl := GetStyle();
|
||||||
|
itmTypInfo := PTypeInfo(GetItemClass().ClassInfo);
|
||||||
arrayLen := nativObj.Length;
|
arrayLen := nativObj.Length;
|
||||||
if ( arrayLen > 0 ) then begin
|
if ( arrayLen > 0 ) then begin
|
||||||
itmTypInfo := PTypeInfo(GetItemClass().ClassInfo);
|
|
||||||
AStore.BeginArray(AName,PTypeInfo(Self.ClassInfo),itmTypInfo,[0,Pred(arrayLen)],styl);
|
AStore.BeginArray(AName,PTypeInfo(Self.ClassInfo),itmTypInfo,[0,Pred(arrayLen)],styl);
|
||||||
try
|
try
|
||||||
if ( styl = asScoped ) then begin
|
if ( styl = asScoped ) then begin
|
||||||
@ -5627,80 +5632,14 @@ end;
|
|||||||
|
|
||||||
{ TDateRemotable }
|
{ TDateRemotable }
|
||||||
|
|
||||||
class function TDateRemotable.FormatDate(const ADate: TDateTimeRec): string;
|
class function TDateRemotable.ToStr(const ADate: TDateTimeRec): string;
|
||||||
begin
|
begin
|
||||||
Result := xsd_DateTimeToStr(ADate);
|
Result := xsd_DateTimeToStr(ADate);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TDateRemotable.ParseDate(const ABuffer: string): TDateTime;
|
class function TDateRemotable.Parse(const ABuffer: string): TDateTimeRec;
|
||||||
var
|
|
||||||
buffer : string;
|
|
||||||
bufferPos, bufferLen : PtrUInt;
|
|
||||||
|
|
||||||
function ReadInt() : PtrUInt;
|
|
||||||
var
|
|
||||||
neg : Boolean;
|
|
||||||
s : shortstring;
|
|
||||||
begin
|
|
||||||
neg := False;
|
|
||||||
|
|
||||||
while ( bufferPos <= bufferLen ) and ( buffer[bufferPos] < #33 ) do begin
|
|
||||||
Inc(bufferPos);
|
|
||||||
end;
|
|
||||||
|
|
||||||
if ( bufferPos <= bufferLen ) then begin
|
|
||||||
if ( ABuffer[bufferPos] = '-' ) then begin
|
|
||||||
neg := True;
|
|
||||||
Inc(bufferPos);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
s := '';
|
|
||||||
while ( bufferPos <= bufferLen ) and ( buffer[bufferPos] in ['0'..'9'] ) do begin
|
|
||||||
s := s + buffer[bufferPos];
|
|
||||||
Inc(bufferPos);
|
|
||||||
end;
|
|
||||||
if ( Length(s) = 0 ) then
|
|
||||||
raise EServiceException.Create('Invalid INTEGER BUFFER');
|
|
||||||
Result := StrToInt(s);
|
|
||||||
if neg then begin
|
|
||||||
Result := -Result;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
d, m, y : Word;
|
|
||||||
hh, mn, ss : Word;
|
|
||||||
begin
|
begin
|
||||||
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
Result := xsd_StrToDate(ABuffer);
|
||||||
|
|
||||||
buffer := Trim(ABuffer);
|
|
||||||
bufferPos := 1;
|
|
||||||
bufferLen := Length(buffer);
|
|
||||||
if ( bufferLen > 0 ) then begin
|
|
||||||
y := ReadInt();
|
|
||||||
Inc(bufferPos);
|
|
||||||
|
|
||||||
m := ReadInt();
|
|
||||||
Inc(bufferPos);
|
|
||||||
|
|
||||||
d := ReadInt();
|
|
||||||
Inc(bufferPos);
|
|
||||||
|
|
||||||
hh := ReadInt();
|
|
||||||
Inc(bufferPos);
|
|
||||||
|
|
||||||
mn := ReadInt();
|
|
||||||
Inc(bufferPos);
|
|
||||||
|
|
||||||
ss := ReadInt();
|
|
||||||
|
|
||||||
if ( ( y + m + d + hh + mn + ss ) = 0 ) then
|
|
||||||
Result := 0
|
|
||||||
else
|
|
||||||
Result := EncodeDate(y,m,d) + EncodeTime(hh,mn,ss,0);
|
|
||||||
end else begin
|
|
||||||
Result := 0;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDateRemotable.GetDatepart(const AIndex: Integer): Integer;
|
function TDateRemotable.GetDatepart(const AIndex: Integer): Integer;
|
||||||
@ -5736,7 +5675,7 @@ class procedure TBaseDateRemotable.Save(
|
|||||||
var
|
var
|
||||||
buffer : string;
|
buffer : string;
|
||||||
begin
|
begin
|
||||||
buffer := FormatDate(TDateRemotable(AObject).AsDate);
|
buffer := TDateRemotable(AObject).AsString;
|
||||||
AStore.BeginObject(AName,ATypeInfo);
|
AStore.BeginObject(AName,ATypeInfo);
|
||||||
try
|
try
|
||||||
AStore.PutScopeInnerValue(TypeInfo(string),buffer);
|
AStore.PutScopeInnerValue(TypeInfo(string),buffer);
|
||||||
@ -5758,7 +5697,7 @@ begin
|
|||||||
try
|
try
|
||||||
strBuffer := '';
|
strBuffer := '';
|
||||||
AStore.GetScopeInnerValue(TypeInfo(string),strBuffer);
|
AStore.GetScopeInnerValue(TypeInfo(string),strBuffer);
|
||||||
(AObject as TDateRemotable).AsDate := ParseDate(strBuffer);
|
(AObject as TDateRemotable).AsString := strBuffer
|
||||||
finally
|
finally
|
||||||
AStore.EndScopeRead();
|
AStore.EndScopeRead();
|
||||||
end;
|
end;
|
||||||
@ -5805,6 +5744,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TBaseDateRemotable.GetAsString: string;
|
||||||
|
begin
|
||||||
|
Result := ToStr(FDate);
|
||||||
|
end;
|
||||||
|
|
||||||
function TBaseDateRemotable.GetOffset(const Index: Integer): Shortint;
|
function TBaseDateRemotable.GetOffset(const Index: Integer): Shortint;
|
||||||
begin
|
begin
|
||||||
if ( Index = 0 ) then
|
if ( Index = 0 ) then
|
||||||
@ -5813,6 +5757,11 @@ begin
|
|||||||
Result := FDate.MinuteOffset;
|
Result := FDate.MinuteOffset;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBaseDateRemotable.SetAsString(const AValue: string);
|
||||||
|
begin
|
||||||
|
FDate := Parse(AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBaseDateRemotable.SetOffset(const Index: Integer; const Value: Shortint);
|
procedure TBaseDateRemotable.SetOffset(const Index: Integer; const Value: Shortint);
|
||||||
begin
|
begin
|
||||||
if ( Index = 0 ) then begin
|
if ( Index = 0 ) then begin
|
||||||
@ -5828,14 +5777,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TBaseDateRemotable.FormatDate(const ADate: TDateTime): string;
|
class function TBaseDateRemotable.ToStr(const ADate: TDateTime): string;
|
||||||
var
|
var
|
||||||
locTemp : TDateTimeRec;
|
locTemp : TDateTimeRec;
|
||||||
begin
|
begin
|
||||||
locTemp.Date := ADate;
|
locTemp.Date := ADate;
|
||||||
locTemp.HourOffset := 0;
|
locTemp.HourOffset := 0;
|
||||||
locTemp.MinuteOffset := 0;
|
locTemp.MinuteOffset := 0;
|
||||||
Result := FormatDate(locTemp);
|
Result := ToStr(locTemp);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TComplexInt8SContentRemotable }
|
{ TComplexInt8SContentRemotable }
|
||||||
@ -6434,6 +6383,54 @@ end;
|
|||||||
|
|
||||||
{ TDurationRemotable }
|
{ TDurationRemotable }
|
||||||
|
|
||||||
|
function TDurationRemotable.GetAsString: string;
|
||||||
|
begin
|
||||||
|
Result := ToStr(FData);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDurationRemotable.GetNegative: Boolean;
|
||||||
|
begin
|
||||||
|
Result := FData.Negative;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TDurationRemotable.GetPart(AIndex: integer): PtrUInt;
|
||||||
|
begin
|
||||||
|
case AIndex of
|
||||||
|
0 : Result := FData.Year;
|
||||||
|
1 : Result := FData.Month;
|
||||||
|
2 : Result := FData.Day;
|
||||||
|
3 : Result := FData.Hour;
|
||||||
|
4 : Result := FData.Minute;
|
||||||
|
5 : Result := FData.Second;
|
||||||
|
6 : Result := FData.FractionalSecond;
|
||||||
|
else
|
||||||
|
Result := 0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDurationRemotable.SetAsString(const AValue: string);
|
||||||
|
begin
|
||||||
|
FData := Parse(AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDurationRemotable.SetNegative(const AValue: Boolean);
|
||||||
|
begin
|
||||||
|
FData.Negative := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TDurationRemotable.SetPart(AIndex: integer; const AValue: PtrUInt);
|
||||||
|
begin
|
||||||
|
case AIndex of
|
||||||
|
0 : FData.Year := AValue;
|
||||||
|
1 : FData.Month := AValue;
|
||||||
|
2 : FData.Day := AValue;
|
||||||
|
3 : FData.Hour := AValue;
|
||||||
|
4 : FData.Minute := AValue;
|
||||||
|
5 : FData.Second := AValue;
|
||||||
|
6 : FData.FractionalSecond := AValue;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TDurationRemotable.Save(
|
class procedure TDurationRemotable.Save(
|
||||||
AObject : TBaseRemotable;
|
AObject : TBaseRemotable;
|
||||||
AStore : IFormatterBase;
|
AStore : IFormatterBase;
|
||||||
@ -6443,7 +6440,7 @@ class procedure TDurationRemotable.Save(
|
|||||||
var
|
var
|
||||||
buffer : string;
|
buffer : string;
|
||||||
begin
|
begin
|
||||||
buffer := TDurationRemotable(AObject).AsString();
|
buffer := TDurationRemotable(AObject).AsString;
|
||||||
AStore.BeginObject(AName,ATypeInfo);
|
AStore.BeginObject(AName,ATypeInfo);
|
||||||
try
|
try
|
||||||
AStore.PutScopeInnerValue(TypeInfo(string),buffer);
|
AStore.PutScopeInnerValue(TypeInfo(string),buffer);
|
||||||
@ -6473,180 +6470,38 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDurationRemotable.Assign(Source : TPersistent);
|
procedure TDurationRemotable.Assign(Source : TPersistent);
|
||||||
var
|
|
||||||
src : TDurationRemotable;
|
|
||||||
begin
|
begin
|
||||||
if ( Source <> nil ) and Source.InheritsFrom(TDurationRemotable) then begin
|
if ( Source <> nil ) and Source.InheritsFrom(TDurationRemotable) then
|
||||||
src := TDurationRemotable(Source);
|
Self.FData := TDurationRemotable(Source).FData
|
||||||
Self.FYear := src.FYear;
|
else
|
||||||
Self.FMonth := src.FMonth;
|
|
||||||
Self.FDay := src.FDay;
|
|
||||||
Self.FHour := src.FHour;
|
|
||||||
Self.FMinute := src.FMinute;
|
|
||||||
Self.FSecond := src.FSecond;
|
|
||||||
Self.FFractionalSecond := src.FFractionalSecond;
|
|
||||||
end else begin
|
|
||||||
inherited Assign(Source);
|
inherited Assign(Source);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDurationRemotable.Equal(const ACompareTo : TBaseRemotable) : Boolean;
|
function TDurationRemotable.Equal(const ACompareTo : TBaseRemotable) : Boolean;
|
||||||
var
|
|
||||||
src : TDurationRemotable;
|
|
||||||
begin
|
begin
|
||||||
if ( Self = ACompareTo ) then begin
|
if ( Self = ACompareTo ) then begin
|
||||||
Result := True;
|
Result := True;
|
||||||
end else begin
|
end else begin
|
||||||
if ( ACompareTo <> nil ) and ACompareTo.InheritsFrom(TDurationRemotable) then begin
|
if ( ACompareTo <> nil ) and ACompareTo.InheritsFrom(TDurationRemotable) then
|
||||||
src := TDurationRemotable(ACompareTo);
|
Result := ValueEquals(Self.FData,TDurationRemotable(ACompareTo).FData)
|
||||||
Result := ( Self.FYear = src.FYear ) and
|
else
|
||||||
( Self.FMonth = src.FMonth ) and
|
|
||||||
( Self.FDay = src.FDay ) and
|
|
||||||
( Self.FHour = src.FHour ) and
|
|
||||||
( Self.FMinute = src.FMinute ) and
|
|
||||||
( Self.FSecond = src.FSecond ) and
|
|
||||||
( Self.FFractionalSecond = src.FFractionalSecond );
|
|
||||||
end else begin
|
|
||||||
Result := inherited Equal(ACompareTo);
|
Result := inherited Equal(ACompareTo);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDurationRemotable.Clear();
|
procedure TDurationRemotable.Clear();
|
||||||
begin
|
begin
|
||||||
FYear := 0;
|
FData := ZERO_DURATION;
|
||||||
FMonth := 0;
|
|
||||||
FDay := 0;
|
|
||||||
FHour := 0;
|
|
||||||
FMinute := 0;
|
|
||||||
FSecond := 0;
|
|
||||||
FFractionalSecond := 0;
|
|
||||||
FNegative := False;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
type TDatePart = ( dpNone, dpYear, dpMonth, dpDay, dpHour, dpMinute, dpSecond, dpFractionalSecond );
|
class function TDurationRemotable.Parse(const ABuffer : string) : TDurationRec;
|
||||||
procedure TDurationRemotable.Parse(const ABuffer : string);
|
|
||||||
|
|
||||||
procedure RaiseInvalidBuffer();
|
|
||||||
begin
|
|
||||||
raise EConvertError.CreateFmt('Invalid duration string : ',[ABuffer]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
pc : PChar;
|
|
||||||
locIntBuffer : array[dpYear..dpFractionalSecond] of PtrUInt;
|
|
||||||
i, bufferLength, lastPos : PtrInt;
|
|
||||||
localBuffer : string;
|
|
||||||
part, oldPart : TDatePart;
|
|
||||||
inTimePart : Boolean;
|
|
||||||
isNeg : Boolean;
|
|
||||||
begin
|
begin
|
||||||
bufferLength := Length(ABuffer);
|
Result := xsd_StrToDuration(ABuffer);
|
||||||
if ( bufferLength < 3 ) then
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
pc := PChar(ABuffer);
|
|
||||||
i := 1;
|
|
||||||
isNeg := False;
|
|
||||||
if ( pc^ = '-' ) then begin
|
|
||||||
Inc(pc); Inc(i);
|
|
||||||
isNeg := True;
|
|
||||||
end;
|
|
||||||
if ( pc^ <> 'P' ) then
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
Inc(pc); Inc(i); //eat 'P'
|
|
||||||
FillChar(locIntBuffer,SizeOf(locIntBuffer),#0);
|
|
||||||
part := dpNone;
|
|
||||||
inTimePart := False;
|
|
||||||
|
|
||||||
if ( pc^ = 'T' ) then begin
|
|
||||||
inTimePart := True;
|
|
||||||
Inc(pc); Inc(i);
|
|
||||||
end;
|
|
||||||
repeat
|
|
||||||
lastPos := i;
|
|
||||||
while ( i < bufferLength ) and ( pc^ in ['0'..'9'] ) do begin
|
|
||||||
Inc(pc); Inc(i);
|
|
||||||
end;
|
|
||||||
if ( ( lastPos = i ) and ( pc^ <> 'T' ) ) then
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
localBuffer := Copy(ABuffer,lastPos,( i - lastPos ));
|
|
||||||
oldPart := part;
|
|
||||||
case pc^ of
|
|
||||||
'Y' : part := dpYear;
|
|
||||||
'M' :
|
|
||||||
begin
|
|
||||||
if inTimePart then
|
|
||||||
part := dpMinute
|
|
||||||
else
|
|
||||||
part := dpMonth;
|
|
||||||
end;
|
|
||||||
'D' : part := dpDay;
|
|
||||||
'H' : part := dpHour;
|
|
||||||
'S', '.' :
|
|
||||||
begin
|
|
||||||
if ( part < dpSecond ) then
|
|
||||||
part := dpSecond
|
|
||||||
else
|
|
||||||
part := dpFractionalSecond;
|
|
||||||
end;
|
|
||||||
'T' :
|
|
||||||
begin
|
|
||||||
inTimePart := True;
|
|
||||||
oldPart := dpNone;
|
|
||||||
part := dpNone;
|
|
||||||
end;
|
|
||||||
else
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
end;
|
|
||||||
if inTimePart and ( part in [dpYear..dpDay] ) then
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
if ( part > dpNone ) then begin
|
|
||||||
if ( part < oldPart ) then
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
locIntBuffer[part] := StrToInt(localBuffer);
|
|
||||||
end;
|
|
||||||
Inc(pc); Inc(i);
|
|
||||||
until ( i >= bufferLength );
|
|
||||||
if ( i = bufferLength ) then
|
|
||||||
RaiseInvalidBuffer();
|
|
||||||
FNegative := isNeg;
|
|
||||||
FYear := locIntBuffer[dpYear];
|
|
||||||
FMonth := locIntBuffer[dpMonth];
|
|
||||||
FDay := locIntBuffer[dpDay];
|
|
||||||
FHour := locIntBuffer[dpHour];
|
|
||||||
FMinute := locIntBuffer[dpMinute];
|
|
||||||
FSecond := locIntBuffer[dpSecond];
|
|
||||||
FFractionalSecond := locIntBuffer[dpFractionalSecond];
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDurationRemotable.AsString() : string;
|
class function TDurationRemotable.ToStr(const AValue: TDurationRec): string;
|
||||||
var
|
|
||||||
strTime, strDate : string;
|
|
||||||
begin
|
begin
|
||||||
if ( FractionalSecond > 0 ) then begin
|
Result := xsd_DurationToStr(AValue);
|
||||||
strTime := IntToStr(Second) + '.' + IntToStr(FractionalSecond) + 'S';
|
|
||||||
end else begin
|
|
||||||
if ( Second > 0 ) then
|
|
||||||
strTime := IntToStr(Second) + 'S';
|
|
||||||
end;
|
|
||||||
if ( Minute > 0 ) then
|
|
||||||
strTime := IntToStr(Minute) + 'M' + strTime;
|
|
||||||
if ( Hour > 0 ) then
|
|
||||||
strTime := IntToStr(Hour) + 'H' + strTime;
|
|
||||||
if ( Day > 0 ) then
|
|
||||||
strDate := IntToStr(Day) + 'D';
|
|
||||||
if ( Month > 0 ) then
|
|
||||||
strDate := IntToStr(Month) + 'M' + strDate;
|
|
||||||
if ( Year > 0 ) then
|
|
||||||
strDate := IntToStr(Year) + 'Y' + strDate;
|
|
||||||
if ( strTime <> '' ) then
|
|
||||||
Result := 'T' + strTime;
|
|
||||||
Result := strDate + Result;
|
|
||||||
if ( Result = '' ) then
|
|
||||||
Result := '0Y';
|
|
||||||
Result := 'P' + Result;
|
|
||||||
if Negative and ( ( strDate <> '' ) or ( strTime <> '' ) ) then
|
|
||||||
Result := '-' + Result;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TRemotableTypeInitializer }
|
{ TRemotableTypeInitializer }
|
||||||
@ -6888,7 +6743,7 @@ end;
|
|||||||
|
|
||||||
function TTimeRemotable.GetAsString : string;
|
function TTimeRemotable.GetAsString : string;
|
||||||
begin
|
begin
|
||||||
Result := ToString(Data);
|
Result := ToStr(Data);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TTimeRemotable.GetMilliSecond: Word;
|
function TTimeRemotable.GetMilliSecond: Word;
|
||||||
@ -7002,10 +6857,10 @@ end;
|
|||||||
function TTimeRemotable.Equal(const ACompareTo: TBaseRemotable): Boolean;
|
function TTimeRemotable.Equal(const ACompareTo: TBaseRemotable): Boolean;
|
||||||
begin
|
begin
|
||||||
if ( ACompareTo = nil ) then begin
|
if ( ACompareTo = nil ) then begin
|
||||||
Result := date_utils.Equals(Data,ZERO_TIME );
|
Result := ValueEquals(Data,ZERO_TIME );
|
||||||
end else begin
|
end else begin
|
||||||
if ACompareTo.InheritsFrom(TTimeRemotable) then
|
if ACompareTo.InheritsFrom(TTimeRemotable) then
|
||||||
Result := date_utils.Equals(Self.Data,TTimeRemotable(ACompareTo).Data)
|
Result := ValueEquals(Self.Data,TTimeRemotable(ACompareTo).Data)
|
||||||
else
|
else
|
||||||
Result := inherited Equal(ACompareTo);
|
Result := inherited Equal(ACompareTo);
|
||||||
end;
|
end;
|
||||||
@ -7021,7 +6876,7 @@ begin
|
|||||||
Result := xsd_StrToTime(ABuffer);
|
Result := xsd_StrToTime(ABuffer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TTimeRemotable.ToString(const AValue: TTimeRec): string;
|
class function TTimeRemotable.ToStr(const AValue: TTimeRec): string;
|
||||||
begin
|
begin
|
||||||
Result := xsd_TimeToStr(AValue);
|
Result := xsd_TimeToStr(AValue);
|
||||||
end;
|
end;
|
||||||
|
@ -14,7 +14,7 @@ unit date_utils;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
uses
|
uses
|
||||||
SysUtils;
|
SysUtils, wst_types;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -33,6 +33,17 @@ type
|
|||||||
MinuteOffset : Shortint;
|
MinuteOffset : Shortint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TDurationRec = packed record
|
||||||
|
Year : PtrUInt;
|
||||||
|
Month : PtrUInt;
|
||||||
|
Day : PtrUInt;
|
||||||
|
Hour : PtrUInt;
|
||||||
|
Minute : PtrUInt;
|
||||||
|
Second : PtrUInt;
|
||||||
|
FractionalSecond : PtrUInt;
|
||||||
|
Negative : Boolean;
|
||||||
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
ZERO_DATE : TDateTimeRec = ( Date : 0; HourOffset : 0; MinuteOffset : 0; );
|
ZERO_DATE : TDateTimeRec = ( Date : 0; HourOffset : 0; MinuteOffset : 0; );
|
||||||
ZERO_TIME : TTimeRec = (
|
ZERO_TIME : TTimeRec = (
|
||||||
@ -43,6 +54,16 @@ const
|
|||||||
HourOffset : 0;
|
HourOffset : 0;
|
||||||
MinuteOffset : 0;
|
MinuteOffset : 0;
|
||||||
);
|
);
|
||||||
|
ZERO_DURATION : TDurationRec = (
|
||||||
|
Year : 0;
|
||||||
|
Month : 0;
|
||||||
|
Day : 0;
|
||||||
|
Hour : 0;
|
||||||
|
Minute : 0;
|
||||||
|
Second : 0;
|
||||||
|
FractionalSecond : 0;
|
||||||
|
Negative : False;
|
||||||
|
);
|
||||||
|
|
||||||
function xsd_TryStrToDate(const AStr : string; out ADate : TDateTimeRec) : Boolean;
|
function xsd_TryStrToDate(const AStr : string; out ADate : TDateTimeRec) : Boolean;
|
||||||
function xsd_StrToDate(const AStr : string) : TDateTimeRec; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
function xsd_StrToDate(const AStr : string) : TDateTimeRec; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||||
@ -70,18 +91,26 @@ const
|
|||||||
function DateTimeToTimeRec(const ADateTime : TDateTime) : TTimeRec; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
function DateTimeToTimeRec(const ADateTime : TDateTime) : TTimeRec; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||||
function TimeRecToDateTime(const ATime : TTimeRec) : TDateTime; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
function TimeRecToDateTime(const ATime : TTimeRec) : TDateTime; {$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||||
|
|
||||||
|
function xsd_TryStrToDuration(
|
||||||
|
const ABuffer : string;
|
||||||
|
out AResult : TDurationRec
|
||||||
|
) : Boolean;
|
||||||
|
function xsd_StrToDuration(const ABuffer : string) : TDurationRec;
|
||||||
|
function xsd_DurationToStr(const AValue : TDurationRec) : string;
|
||||||
|
|
||||||
function IncHour(const AValue: TDateTime; const ANumberOfHours: Int64): TDateTime;{$IFDEF USE_INLINE}inline;{$ENDIF}
|
function IncHour(const AValue: TDateTime; const ANumberOfHours: Int64): TDateTime;{$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||||
function IncMinute(const AValue: TDateTime; const ANumberOfMinutes: Int64): TDateTime;{$IFDEF USE_INLINE}inline;{$ENDIF}
|
function IncMinute(const AValue: TDateTime; const ANumberOfMinutes: Int64): TDateTime;{$IFDEF USE_INLINE}inline;{$ENDIF}
|
||||||
|
|
||||||
function NormalizeToUTC(const ADate : TDateTimeRec) : TDateTime; overload;
|
function NormalizeToUTC(const ADate : TDateTimeRec) : TDateTime; overload;
|
||||||
function NormalizeToUTC(const ATime : TTimeRec) : TTimeRec; overload;
|
function NormalizeToUTC(const ATime : TTimeRec) : TTimeRec; overload;
|
||||||
function Equals(const AA,AB: TDateTimeRec) : Boolean; overload;
|
function ValueEquals(const AA,AB: TDateTimeRec) : Boolean; overload;
|
||||||
function Equals(const AA,AB: TTimeRec) : Boolean; overload;
|
function ValueEquals(const AA,AB: TTimeRec) : Boolean; overload;
|
||||||
|
function ValueEquals(const AA,AB: TDurationRec) : Boolean; overload;
|
||||||
|
|
||||||
resourcestring
|
resourcestring
|
||||||
SERR_InvalidDate = '"%s" is not a valid date.';
|
SERR_InvalidDate = '"%s" is not a valid date.';
|
||||||
SERR_InvalidTime = '"%s" is not a valid time.';
|
SERR_InvalidTime = '"%s" is not a valid time.';
|
||||||
|
SERR_InvalidDuration = '"%s" is not a valid duration.';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -126,7 +155,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{$HINTS OFF}
|
{$HINTS OFF}
|
||||||
function Equals(const AA,AB: TDateTimeRec) : Boolean;
|
function ValueEquals(const AA,AB: TDateTimeRec) : Boolean;
|
||||||
var
|
var
|
||||||
e, a : TDateTime;
|
e, a : TDateTime;
|
||||||
e_y, e_m, e_d, e_h, e_mn, e_ss, e_ms : Word;
|
e_y, e_m, e_d, e_h, e_mn, e_ss, e_ms : Word;
|
||||||
@ -141,7 +170,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$HINTS ON}
|
{$HINTS ON}
|
||||||
|
|
||||||
function Equals(const AA,AB: TTimeRec) : Boolean;
|
function ValueEquals(const AA,AB: TTimeRec) : Boolean;
|
||||||
var
|
var
|
||||||
a, b : TTimeRec;
|
a, b : TTimeRec;
|
||||||
begin
|
begin
|
||||||
@ -523,4 +552,147 @@ begin
|
|||||||
Result := EncodeTime(ATime.Hour,ATime.Minute,ATime.Second,ATime.MilliSecond);
|
Result := EncodeTime(ATime.Hour,ATime.Minute,ATime.Second,ATime.MilliSecond);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
type TDatePart = ( dpNone, dpYear, dpMonth, dpDay, dpHour, dpMinute, dpSecond, dpFractionalSecond );
|
||||||
|
function xsd_TryStrToDuration(
|
||||||
|
const ABuffer : string;
|
||||||
|
out AResult : TDurationRec
|
||||||
|
) : Boolean;
|
||||||
|
var
|
||||||
|
pc : PChar;
|
||||||
|
locIntBuffer : array[dpYear..dpFractionalSecond] of PtrUInt;
|
||||||
|
i, bufferLength, lastPos : PtrInt;
|
||||||
|
localBuffer : string;
|
||||||
|
part, oldPart : TDatePart;
|
||||||
|
inTimePart : Boolean;
|
||||||
|
isNeg : Boolean;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
bufferLength := Length(ABuffer);
|
||||||
|
if ( bufferLength < 3 ) then
|
||||||
|
Exit;
|
||||||
|
pc := PChar(ABuffer);
|
||||||
|
i := 1;
|
||||||
|
isNeg := False;
|
||||||
|
if ( pc^ = '-' ) then begin
|
||||||
|
Inc(pc); Inc(i);
|
||||||
|
isNeg := True;
|
||||||
|
end;
|
||||||
|
if ( pc^ <> 'P' ) then
|
||||||
|
Exit;
|
||||||
|
Inc(pc); Inc(i); //eat 'P'
|
||||||
|
FillChar(locIntBuffer,SizeOf(locIntBuffer),#0);
|
||||||
|
part := dpNone;
|
||||||
|
inTimePart := False;
|
||||||
|
|
||||||
|
if ( pc^ = 'T' ) then begin
|
||||||
|
inTimePart := True;
|
||||||
|
Inc(pc); Inc(i);
|
||||||
|
end;
|
||||||
|
repeat
|
||||||
|
lastPos := i;
|
||||||
|
while ( i < bufferLength ) and ( pc^ in ['0'..'9'] ) do begin
|
||||||
|
Inc(pc); Inc(i);
|
||||||
|
end;
|
||||||
|
if ( ( lastPos = i ) and ( pc^ <> 'T' ) ) then
|
||||||
|
Exit;
|
||||||
|
localBuffer := Copy(ABuffer,lastPos,( i - lastPos ));
|
||||||
|
oldPart := part;
|
||||||
|
case pc^ of
|
||||||
|
'Y' : part := dpYear;
|
||||||
|
'M' :
|
||||||
|
begin
|
||||||
|
if inTimePart then
|
||||||
|
part := dpMinute
|
||||||
|
else
|
||||||
|
part := dpMonth;
|
||||||
|
end;
|
||||||
|
'D' : part := dpDay;
|
||||||
|
'H' : part := dpHour;
|
||||||
|
'S', '.' :
|
||||||
|
begin
|
||||||
|
if ( part < dpSecond ) then
|
||||||
|
part := dpSecond
|
||||||
|
else
|
||||||
|
part := dpFractionalSecond;
|
||||||
|
end;
|
||||||
|
'T' :
|
||||||
|
begin
|
||||||
|
inTimePart := True;
|
||||||
|
oldPart := dpNone;
|
||||||
|
part := dpNone;
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
if inTimePart and ( part in [dpYear..dpDay] ) then
|
||||||
|
Exit;
|
||||||
|
if ( part > dpNone ) then begin
|
||||||
|
if ( part < oldPart ) then
|
||||||
|
Exit;
|
||||||
|
locIntBuffer[part] := StrToInt(localBuffer);
|
||||||
|
end;
|
||||||
|
Inc(pc); Inc(i);
|
||||||
|
until ( i >= bufferLength );
|
||||||
|
if ( i = bufferLength ) then
|
||||||
|
Exit;
|
||||||
|
AResult.Negative := isNeg;
|
||||||
|
AResult.Year := locIntBuffer[dpYear];
|
||||||
|
AResult.Month := locIntBuffer[dpMonth];
|
||||||
|
AResult.Day := locIntBuffer[dpDay];
|
||||||
|
AResult.Hour := locIntBuffer[dpHour];
|
||||||
|
AResult.Minute := locIntBuffer[dpMinute];
|
||||||
|
AResult.Second := locIntBuffer[dpSecond];
|
||||||
|
AResult.FractionalSecond := locIntBuffer[dpFractionalSecond];
|
||||||
|
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function xsd_StrToDuration(const ABuffer : string) : TDurationRec;
|
||||||
|
begin
|
||||||
|
if not xsd_TryStrToDuration(ABuffer,Result) then
|
||||||
|
raise EConvertError.CreateFmt(SERR_InvalidDuration,[ABuffer]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function xsd_DurationToStr(const AValue : TDurationRec) : string;
|
||||||
|
var
|
||||||
|
strTime, strDate : string;
|
||||||
|
begin
|
||||||
|
if ( AValue.FractionalSecond > 0 ) then begin
|
||||||
|
strTime := IntToStr(AValue.Second) + '.' + IntToStr(AValue.FractionalSecond) + 'S';
|
||||||
|
end else begin
|
||||||
|
if ( AValue.Second > 0 ) then
|
||||||
|
strTime := IntToStr(AValue.Second) + 'S';
|
||||||
|
end;
|
||||||
|
if ( AValue.Minute > 0 ) then
|
||||||
|
strTime := IntToStr(AValue.Minute) + 'M' + strTime;
|
||||||
|
if ( AValue.Hour > 0 ) then
|
||||||
|
strTime := IntToStr(AValue.Hour) + 'H' + strTime;
|
||||||
|
if ( AValue.Day > 0 ) then
|
||||||
|
strDate := IntToStr(AValue.Day) + 'D';
|
||||||
|
if ( AValue.Month > 0 ) then
|
||||||
|
strDate := IntToStr(AValue.Month) + 'M' + strDate;
|
||||||
|
if ( AValue.Year > 0 ) then
|
||||||
|
strDate := IntToStr(AValue.Year) + 'Y' + strDate;
|
||||||
|
if ( strTime <> '' ) then
|
||||||
|
Result := 'T' + strTime;
|
||||||
|
Result := strDate + Result;
|
||||||
|
if ( Result = '' ) then
|
||||||
|
Result := '0Y';
|
||||||
|
Result := 'P' + Result;
|
||||||
|
if AValue.Negative and ( ( strDate <> '' ) or ( strTime <> '' ) ) then
|
||||||
|
Result := '-' + Result;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ValueEquals(const AA,AB: TDurationRec) : Boolean;
|
||||||
|
begin
|
||||||
|
Result := ( AA.Negative = AB.Negative ) and
|
||||||
|
( AA.Year = AB.Year ) and
|
||||||
|
( AA.Month = AB.Month ) and
|
||||||
|
( AA.Day = AB.Day ) and
|
||||||
|
( AA.Hour = AB.Hour ) and
|
||||||
|
( AA.Minute = AB.Minute ) and
|
||||||
|
( AA.Second = AB.Second ) and
|
||||||
|
( AA.FractionalSecond = AB.FractionalSecond );
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -346,7 +346,7 @@ type
|
|||||||
procedure CheckEquals(expected, actual: TTimeRec; msg: string = ''); overload;
|
procedure CheckEquals(expected, actual: TTimeRec; msg: string = ''); overload;
|
||||||
{$ENDIF WST_DELPHI}
|
{$ENDIF WST_DELPHI}
|
||||||
published
|
published
|
||||||
procedure ToString();
|
procedure ToStr();
|
||||||
procedure Parse();
|
procedure Parse();
|
||||||
procedure Parse_millisecond();
|
procedure Parse_millisecond();
|
||||||
procedure Parse_offset_1();
|
procedure Parse_offset_1();
|
||||||
@ -2251,36 +2251,34 @@ var
|
|||||||
begin
|
begin
|
||||||
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
||||||
d := EncodeDate(1976,10,12) + EncodeTime(23,34,56,0);
|
d := EncodeDate(1976,10,12) + EncodeTime(23,34,56,0);
|
||||||
CheckEquals(sDATE_1, Copy(TDateRemotable.FormatDate(d),1,Length(sDATE_1)));
|
CheckEquals(sDATE_1, Copy(TDateRemotable.ToStr(d),1,Length(sDATE_1)));
|
||||||
|
|
||||||
d := EncodeDate(987,06,12) - EncodeTime(20,34,56,0);
|
d := EncodeDate(987,06,12) - EncodeTime(20,34,56,0);
|
||||||
CheckEquals(sDATE_2, Copy(TDateRemotable.FormatDate(d),1,Length(sDATE_2)));
|
CheckEquals(sDATE_2, Copy(TDateRemotable.ToStr(d),1,Length(sDATE_2)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDateRemotable.ParseDate();
|
procedure TTest_TDateRemotable.ParseDate();
|
||||||
var
|
var
|
||||||
s : string;
|
s : string;
|
||||||
objd : TDateRemotable;
|
objd : TDateRemotable;
|
||||||
d : TDateTime;
|
d : TDateTimeRec;
|
||||||
y,m,dy : Word;
|
y,m,dy : Word;
|
||||||
hh,mn,ss, ssss : Word;
|
hh,mn,ss, ssss : Word;
|
||||||
begin
|
begin
|
||||||
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
||||||
s := '1976-10-12T23:34:56';
|
s := '1976-10-12T23:34:56';
|
||||||
d := TDateRemotable.ParseDate(s);
|
d := TDateRemotable.Parse(s);
|
||||||
DecodeDate(d,y,m,dy);
|
DecodeDateTime(d.Date,y,m,dy, hh,mn,ss,ssss);
|
||||||
CheckEquals(y,1976,'Year');
|
CheckEquals(y,1976,'Year');
|
||||||
CheckEquals(m,10,'Month');
|
CheckEquals(m,10,'Month');
|
||||||
CheckEquals(dy,12,'Day');
|
CheckEquals(dy,12,'Day');
|
||||||
|
|
||||||
DecodeTime(d,hh,mn,ss,ssss);
|
|
||||||
CheckEquals(hh,23,'Hour');
|
CheckEquals(hh,23,'Hour');
|
||||||
CheckEquals(mn,34,'Minute');
|
CheckEquals(mn,34,'Minute');
|
||||||
CheckEquals(ss,56,'Second');
|
CheckEquals(ss,56,'Second');
|
||||||
|
|
||||||
objd := TDateRemotable.Create();
|
objd := TDateRemotable.Create();
|
||||||
try
|
try
|
||||||
objd.AsDate := d;
|
objd.AsDate := d.Date;
|
||||||
CheckEquals(objd.Year,1976,'Year');
|
CheckEquals(objd.Year,1976,'Year');
|
||||||
CheckEquals(objd.Month,10,'Month');
|
CheckEquals(objd.Month,10,'Month');
|
||||||
CheckEquals(objd.Day,12,'Day');
|
CheckEquals(objd.Day,12,'Day');
|
||||||
@ -2352,7 +2350,7 @@ var
|
|||||||
begin
|
begin
|
||||||
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
//'-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
||||||
d := 0;
|
d := 0;
|
||||||
CheckEquals(sDATE, Copy(TDateRemotable.FormatDate(d),1,Length(sDATE)));
|
CheckEquals(sDATE, Copy(TDateRemotable.ToStr(d),1,Length(sDATE)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDateRemotable.AsDate();
|
procedure TTest_TDateRemotable.AsDate();
|
||||||
@ -2558,9 +2556,9 @@ var
|
|||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
try
|
try
|
||||||
CheckEquals('P0Y', x.AsString());
|
CheckEquals('P0Y', x.AsString);
|
||||||
x.Negative := True;
|
x.Negative := True;
|
||||||
CheckEquals('P0Y', x.AsString());
|
CheckEquals('P0Y', x.AsString);
|
||||||
finally
|
finally
|
||||||
x.Free();
|
x.Free();
|
||||||
end;
|
end;
|
||||||
@ -2578,11 +2576,11 @@ begin
|
|||||||
x.Hour := 4;
|
x.Hour := 4;
|
||||||
x.Minute := 5;
|
x.Minute := 5;
|
||||||
x.Second := 6;
|
x.Second := 6;
|
||||||
CheckEquals('P1Y2M3DT4H5M6S',x.AsString());
|
CheckEquals('P1Y2M3DT4H5M6S',x.AsString);
|
||||||
x.FractionalSecond := 7;
|
x.FractionalSecond := 7;
|
||||||
CheckEquals('P1Y2M3DT4H5M6.7S',x.AsString());
|
CheckEquals('P1Y2M3DT4H5M6.7S',x.AsString);
|
||||||
x.Negative := True;
|
x.Negative := True;
|
||||||
CheckEquals('-P1Y2M3DT4H5M6.7S',x.AsString());
|
CheckEquals('-P1Y2M3DT4H5M6.7S',x.AsString);
|
||||||
finally
|
finally
|
||||||
x.Free();
|
x.Free();
|
||||||
end;
|
end;
|
||||||
@ -2595,41 +2593,41 @@ begin
|
|||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
try
|
try
|
||||||
x.Year := 1;
|
x.Year := 1;
|
||||||
CheckEquals('P1Y', x.AsString());
|
CheckEquals('P1Y', x.AsString);
|
||||||
x.Month := 2;
|
x.Month := 2;
|
||||||
CheckEquals('P1Y2M', x.AsString());
|
CheckEquals('P1Y2M', x.AsString);
|
||||||
x.Day := 3;
|
x.Day := 3;
|
||||||
CheckEquals('P1Y2M3D', x.AsString());
|
CheckEquals('P1Y2M3D', x.AsString);
|
||||||
x.Negative := True;
|
x.Negative := True;
|
||||||
CheckEquals('-P1Y2M3D', x.AsString());
|
CheckEquals('-P1Y2M3D', x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Month := 12;
|
x.Month := 12;
|
||||||
CheckEquals('P12M',x.AsString());
|
CheckEquals('P12M',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Day := 34;
|
x.Day := 34;
|
||||||
CheckEquals('P34D',x.AsString());
|
CheckEquals('P34D',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Month := 12;
|
x.Month := 12;
|
||||||
x.Day := 3;
|
x.Day := 3;
|
||||||
CheckEquals('P12M3D',x.AsString());
|
CheckEquals('P12M3D',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Year := 2;
|
x.Year := 2;
|
||||||
x.Month := 34;
|
x.Month := 34;
|
||||||
CheckEquals('P2Y34M',x.AsString());
|
CheckEquals('P2Y34M',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Year := 12;
|
x.Year := 12;
|
||||||
x.Day := 56;
|
x.Day := 56;
|
||||||
CheckEquals('P12Y56D',x.AsString());
|
CheckEquals('P12Y56D',x.AsString);
|
||||||
finally
|
finally
|
||||||
x.Free();
|
x.Free();
|
||||||
end;
|
end;
|
||||||
@ -2642,43 +2640,43 @@ begin
|
|||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
try
|
try
|
||||||
x.Hour := 1;
|
x.Hour := 1;
|
||||||
CheckEquals('PT1H', x.AsString());
|
CheckEquals('PT1H', x.AsString);
|
||||||
x.Minute := 2;
|
x.Minute := 2;
|
||||||
CheckEquals('PT1H2M', x.AsString());
|
CheckEquals('PT1H2M', x.AsString);
|
||||||
x.Second := 3;
|
x.Second := 3;
|
||||||
CheckEquals('PT1H2M3S', x.AsString());
|
CheckEquals('PT1H2M3S', x.AsString);
|
||||||
x.FractionalSecond := 4;
|
x.FractionalSecond := 4;
|
||||||
CheckEquals('PT1H2M3.4S', x.AsString());
|
CheckEquals('PT1H2M3.4S', x.AsString);
|
||||||
x.Negative := True;
|
x.Negative := True;
|
||||||
CheckEquals('-PT1H2M3.4S', x.AsString());
|
CheckEquals('-PT1H2M3.4S', x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Minute := 12;
|
x.Minute := 12;
|
||||||
CheckEquals('PT12M',x.AsString());
|
CheckEquals('PT12M',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Second := 34;
|
x.Second := 34;
|
||||||
CheckEquals('PT34S',x.AsString());
|
CheckEquals('PT34S',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Minute := 12;
|
x.Minute := 12;
|
||||||
x.Second := 3;
|
x.Second := 3;
|
||||||
CheckEquals('PT12M3S',x.AsString());
|
CheckEquals('PT12M3S',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Hour := 2;
|
x.Hour := 2;
|
||||||
x.Minute := 34;
|
x.Minute := 34;
|
||||||
CheckEquals('PT2H34M',x.AsString());
|
CheckEquals('PT2H34M',x.AsString);
|
||||||
|
|
||||||
FreeAndNil(x);
|
FreeAndNil(x);
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Create();
|
||||||
x.Hour := 12;
|
x.Hour := 12;
|
||||||
x.Second := 56;
|
x.Second := 56;
|
||||||
CheckEquals('PT12H56S',x.AsString());
|
CheckEquals('PT12H56S',x.AsString);
|
||||||
finally
|
finally
|
||||||
x.Free();
|
x.Free();
|
||||||
end;
|
end;
|
||||||
@ -2686,289 +2684,212 @@ end;
|
|||||||
|
|
||||||
procedure TTest_TDurationRemotable.Parse_non_empty();
|
procedure TTest_TDurationRemotable.Parse_non_empty();
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
x : TDurationRec;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('P1Y2M3DT4H5M6S');
|
||||||
try
|
CheckEquals(False,x.Negative);
|
||||||
x.Parse('P1Y2M3DT4H5M6S');
|
CheckEquals(1,x.Year);
|
||||||
CheckEquals(False,x.Negative);
|
CheckEquals(2,x.Month);
|
||||||
CheckEquals(1,x.Year);
|
CheckEquals(3,x.Day);
|
||||||
CheckEquals(2,x.Month);
|
CheckEquals(4,x.Hour);
|
||||||
CheckEquals(3,x.Day);
|
CheckEquals(5,x.Minute);
|
||||||
CheckEquals(4,x.Hour);
|
CheckEquals(6,x.Second);
|
||||||
CheckEquals(5,x.Minute);
|
CheckEquals(0,x.FractionalSecond);
|
||||||
CheckEquals(6,x.Second);
|
|
||||||
CheckEquals(0,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
|
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('-P1Y2M3DT4H5M6S');
|
||||||
x.Parse('-P1Y2M3DT4H5M6S');
|
CheckEquals(True,x.Negative);
|
||||||
CheckEquals(True,x.Negative);
|
CheckEquals(1,x.Year);
|
||||||
CheckEquals(1,x.Year);
|
CheckEquals(2,x.Month);
|
||||||
CheckEquals(2,x.Month);
|
CheckEquals(3,x.Day);
|
||||||
CheckEquals(3,x.Day);
|
CheckEquals(4,x.Hour);
|
||||||
CheckEquals(4,x.Hour);
|
CheckEquals(5,x.Minute);
|
||||||
CheckEquals(5,x.Minute);
|
CheckEquals(6,x.Second);
|
||||||
CheckEquals(6,x.Second);
|
CheckEquals(0,x.FractionalSecond);
|
||||||
CheckEquals(0,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
|
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('P1Y2M3DT4H5M6.7S');
|
||||||
x.Parse('P1Y2M3DT4H5M6.7S');
|
CheckEquals(False,x.Negative);
|
||||||
CheckEquals(False,x.Negative);
|
CheckEquals(1,x.Year);
|
||||||
CheckEquals(1,x.Year);
|
CheckEquals(2,x.Month);
|
||||||
CheckEquals(2,x.Month);
|
CheckEquals(3,x.Day);
|
||||||
CheckEquals(3,x.Day);
|
CheckEquals(4,x.Hour);
|
||||||
CheckEquals(4,x.Hour);
|
CheckEquals(5,x.Minute);
|
||||||
CheckEquals(5,x.Minute);
|
CheckEquals(6,x.Second);
|
||||||
CheckEquals(6,x.Second);
|
CheckEquals(7,x.FractionalSecond);
|
||||||
CheckEquals(7,x.FractionalSecond);
|
|
||||||
|
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('-P1Y2M3DT4H5M6.7S');
|
||||||
x.Parse('-P1Y2M3DT4H5M6.7S');
|
CheckEquals(True,x.Negative);
|
||||||
CheckEquals(True,x.Negative);
|
CheckEquals(1,x.Year);
|
||||||
CheckEquals(1,x.Year);
|
CheckEquals(2,x.Month);
|
||||||
CheckEquals(2,x.Month);
|
CheckEquals(3,x.Day);
|
||||||
CheckEquals(3,x.Day);
|
CheckEquals(4,x.Hour);
|
||||||
CheckEquals(4,x.Hour);
|
CheckEquals(5,x.Minute);
|
||||||
CheckEquals(5,x.Minute);
|
CheckEquals(6,x.Second);
|
||||||
CheckEquals(6,x.Second);
|
CheckEquals(7,x.FractionalSecond);
|
||||||
CheckEquals(7,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.Parse_time_only();
|
procedure TTest_TDurationRemotable.Parse_time_only();
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
x : TDurationRec;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('PT1H2M3.4S');
|
||||||
try
|
CheckEquals(False,x.Negative);
|
||||||
x.Parse('PT1H2M3.4S');
|
CheckEquals(0,x.Year);
|
||||||
CheckEquals(False,x.Negative);
|
CheckEquals(0,x.Month);
|
||||||
CheckEquals(0,x.Year);
|
CheckEquals(0,x.Day);
|
||||||
CheckEquals(0,x.Month);
|
CheckEquals(1,x.Hour);
|
||||||
CheckEquals(0,x.Day);
|
CheckEquals(2,x.Minute);
|
||||||
CheckEquals(1,x.Hour);
|
CheckEquals(3,x.Second);
|
||||||
CheckEquals(2,x.Minute);
|
CheckEquals(4,x.FractionalSecond);
|
||||||
CheckEquals(3,x.Second);
|
|
||||||
CheckEquals(4,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
|
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('-PT1H2M3.4S');
|
||||||
x.Parse('-PT1H2M3.4S');
|
CheckEquals(True,x.Negative);
|
||||||
CheckEquals(True,x.Negative);
|
CheckEquals(0,x.Year);
|
||||||
CheckEquals(0,x.Year);
|
CheckEquals(0,x.Month);
|
||||||
CheckEquals(0,x.Month);
|
CheckEquals(0,x.Day);
|
||||||
CheckEquals(0,x.Day);
|
CheckEquals(1,x.Hour);
|
||||||
CheckEquals(1,x.Hour);
|
CheckEquals(2,x.Minute);
|
||||||
CheckEquals(2,x.Minute);
|
CheckEquals(3,x.Second);
|
||||||
CheckEquals(3,x.Second);
|
CheckEquals(4,x.FractionalSecond);
|
||||||
CheckEquals(4,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
|
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('PT1H');
|
||||||
x.Parse('PT1H');
|
CheckEquals(False,x.Negative);
|
||||||
CheckEquals(False,x.Negative);
|
CheckEquals(0,x.Year);
|
||||||
CheckEquals(0,x.Year);
|
CheckEquals(0,x.Month);
|
||||||
CheckEquals(0,x.Month);
|
CheckEquals(0,x.Day);
|
||||||
CheckEquals(0,x.Day);
|
CheckEquals(1,x.Hour);
|
||||||
CheckEquals(1,x.Hour);
|
CheckEquals(0,x.Minute);
|
||||||
CheckEquals(0,x.Minute);
|
CheckEquals(0,x.Second);
|
||||||
CheckEquals(0,x.Second);
|
CheckEquals(0,x.FractionalSecond);
|
||||||
CheckEquals(0,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
|
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('PT1S');
|
||||||
x.Parse('PT1S');
|
|
||||||
CheckEquals(False,x.Negative);
|
|
||||||
CheckEquals(0,x.Year);
|
|
||||||
CheckEquals(0,x.Month);
|
|
||||||
CheckEquals(0,x.Day);
|
|
||||||
CheckEquals(0,x.Hour);
|
|
||||||
CheckEquals(0,x.Minute);
|
|
||||||
CheckEquals(1,x.Second);
|
|
||||||
CheckEquals(0,x.FractionalSecond);
|
|
||||||
FreeAndNil(x);
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.Parse_zero();
|
|
||||||
var
|
|
||||||
x : TDurationRemotable;
|
|
||||||
begin
|
|
||||||
x := TDurationRemotable.Create();
|
|
||||||
try
|
|
||||||
x.Negative := True;
|
|
||||||
x.Year := 1;
|
|
||||||
x.Month := 2;
|
|
||||||
x.Day := 3;
|
|
||||||
x.Hour := 4;
|
|
||||||
x.Minute := 5;
|
|
||||||
x.Second := 6;
|
|
||||||
x.FractionalSecond := 7;
|
|
||||||
x.Parse('P0Y');
|
|
||||||
CheckEquals(False,x.Negative);
|
CheckEquals(False,x.Negative);
|
||||||
CheckEquals(0,x.Year);
|
CheckEquals(0,x.Year);
|
||||||
CheckEquals(0,x.Month);
|
CheckEquals(0,x.Month);
|
||||||
CheckEquals(0,x.Day);
|
CheckEquals(0,x.Day);
|
||||||
CheckEquals(0,x.Hour);
|
CheckEquals(0,x.Hour);
|
||||||
CheckEquals(0,x.Minute);
|
CheckEquals(0,x.Minute);
|
||||||
CheckEquals(0,x.Second);
|
CheckEquals(1,x.Second);
|
||||||
CheckEquals(0,x.FractionalSecond);
|
CheckEquals(0,x.FractionalSecond);
|
||||||
finally
|
end;
|
||||||
x.Free();
|
|
||||||
end;
|
procedure TTest_TDurationRemotable.Parse_zero();
|
||||||
|
var
|
||||||
|
x : TDurationRec;
|
||||||
|
begin
|
||||||
|
x := TDurationRemotable.Parse('P0Y');
|
||||||
|
CheckEquals(False,x.Negative);
|
||||||
|
CheckEquals(0,x.Year);
|
||||||
|
CheckEquals(0,x.Month);
|
||||||
|
CheckEquals(0,x.Day);
|
||||||
|
CheckEquals(0,x.Hour);
|
||||||
|
CheckEquals(0,x.Minute);
|
||||||
|
CheckEquals(0,x.Second);
|
||||||
|
CheckEquals(0,x.FractionalSecond);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_negative();
|
procedure TTest_TDurationRemotable.parse_negative();
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
x : TDurationRec;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
x := TDurationRemotable.Parse('-P3YT4S');
|
||||||
try
|
CheckEquals(True,x.Negative);
|
||||||
x.Parse('-P3YT4S');
|
CheckEquals(3,x.Year);
|
||||||
CheckEquals(True,x.Negative);
|
CheckEquals(0,x.Month);
|
||||||
CheckEquals(3,x.Year);
|
CheckEquals(0,x.Day);
|
||||||
CheckEquals(0,x.Month);
|
CheckEquals(0,x.Hour);
|
||||||
CheckEquals(0,x.Day);
|
CheckEquals(0,x.Minute);
|
||||||
CheckEquals(0,x.Hour);
|
CheckEquals(4,x.Second);
|
||||||
CheckEquals(0,x.Minute);
|
CheckEquals(0,x.FractionalSecond);
|
||||||
CheckEquals(4,x.Second);
|
|
||||||
CheckEquals(0,x.FractionalSecond);
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_invalid_1();
|
procedure TTest_TDurationRemotable.parse_invalid_1();
|
||||||
const S_EXPR = 'P-1347M';
|
const S_EXPR = 'P-1347M';
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
|
||||||
ok : Boolean;
|
ok : Boolean;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
ok := False;
|
||||||
try
|
try
|
||||||
ok := False;
|
TDurationRemotable.Parse(S_EXPR);
|
||||||
try
|
except
|
||||||
x.Parse(S_EXPR);
|
on e : EConvertError do
|
||||||
except
|
ok := True;
|
||||||
on e : EConvertError do
|
|
||||||
ok := True;
|
|
||||||
end;
|
|
||||||
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
end;
|
||||||
|
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_invalid_2();
|
procedure TTest_TDurationRemotable.parse_invalid_2();
|
||||||
const S_EXPR = 'P1Y2MT';
|
const S_EXPR = 'P1Y2MT';
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
|
||||||
ok : Boolean;
|
ok : Boolean;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
ok := False;
|
||||||
try
|
try
|
||||||
ok := False;
|
TDurationRemotable.Parse(S_EXPR);
|
||||||
try
|
except
|
||||||
x.Parse(S_EXPR);
|
on e : EConvertError do
|
||||||
except
|
ok := True;
|
||||||
on e : EConvertError do
|
|
||||||
ok := True;
|
|
||||||
end;
|
|
||||||
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
end;
|
||||||
|
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_invalid_3();
|
procedure TTest_TDurationRemotable.parse_invalid_3();
|
||||||
const S_EXPR = 'XOJDQJKJ';
|
const S_EXPR = 'XOJDQJKJ';
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
|
||||||
ok : Boolean;
|
ok : Boolean;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
ok := False;
|
||||||
try
|
try
|
||||||
ok := False;
|
TDurationRemotable.Parse(S_EXPR);
|
||||||
try
|
except
|
||||||
x.Parse(S_EXPR);
|
on e : EConvertError do
|
||||||
except
|
ok := True;
|
||||||
on e : EConvertError do
|
|
||||||
ok := True;
|
|
||||||
end;
|
|
||||||
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
end;
|
||||||
|
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_invalid_4();
|
procedure TTest_TDurationRemotable.parse_invalid_4();
|
||||||
const S_EXPR = 'P';
|
const S_EXPR = 'P';
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
|
||||||
ok : Boolean;
|
ok : Boolean;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
ok := False;
|
||||||
try
|
try
|
||||||
ok := False;
|
TDurationRemotable.Parse(S_EXPR);
|
||||||
try
|
except
|
||||||
x.Parse(S_EXPR);
|
on e : EConvertError do
|
||||||
except
|
ok := True;
|
||||||
on e : EConvertError do
|
|
||||||
ok := True;
|
|
||||||
end;
|
|
||||||
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
end;
|
||||||
|
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_invalid_5();
|
procedure TTest_TDurationRemotable.parse_invalid_5();
|
||||||
const S_EXPR = 'P45DH';
|
const S_EXPR = 'P45DH';
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
|
||||||
ok : Boolean;
|
ok : Boolean;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
ok := False;
|
||||||
try
|
try
|
||||||
ok := False;
|
TDurationRemotable.Parse(S_EXPR);
|
||||||
try
|
except
|
||||||
x.Parse(S_EXPR);
|
on e : EConvertError do
|
||||||
except
|
ok := True;
|
||||||
on e : EConvertError do
|
|
||||||
ok := True;
|
|
||||||
end;
|
|
||||||
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
end;
|
||||||
|
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TDurationRemotable.parse_empty();
|
procedure TTest_TDurationRemotable.parse_empty();
|
||||||
const S_EXPR = '';
|
const S_EXPR = '';
|
||||||
var
|
var
|
||||||
x : TDurationRemotable;
|
|
||||||
ok : Boolean;
|
ok : Boolean;
|
||||||
begin
|
begin
|
||||||
x := TDurationRemotable.Create();
|
ok := False;
|
||||||
try
|
try
|
||||||
ok := False;
|
TDurationRemotable.Parse(S_EXPR);
|
||||||
try
|
except
|
||||||
x.Parse(S_EXPR);
|
on e : EConvertError do
|
||||||
except
|
ok := True;
|
||||||
on e : EConvertError do
|
|
||||||
ok := True;
|
|
||||||
end;
|
|
||||||
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
|
||||||
finally
|
|
||||||
x.Free();
|
|
||||||
end;
|
end;
|
||||||
|
Check(ok, Format('Must fail with : "%s"',[S_EXPR]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TTest_TTimeRemotable }
|
{ TTest_TTimeRemotable }
|
||||||
@ -2996,7 +2917,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$ENDIF FPC}
|
{$ENDIF FPC}
|
||||||
|
|
||||||
procedure TTest_TTimeRemotable.ToString();
|
procedure TTest_TTimeRemotable.ToStr();
|
||||||
const
|
const
|
||||||
sVALUE_1 = '01:23:45.678';
|
sVALUE_1 = '01:23:45.678';
|
||||||
sVALUE_2 = '12:34:56';
|
sVALUE_2 = '12:34:56';
|
||||||
@ -3006,13 +2927,13 @@ var
|
|||||||
begin
|
begin
|
||||||
//hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
//hh ':' mm ':' ss ('.' s+)? (zzzzzz)?
|
||||||
d := xsd_EncodeTime(01,23,45,678);
|
d := xsd_EncodeTime(01,23,45,678);
|
||||||
CheckEquals(sVALUE_1, Copy(TTimeRemotable.ToString(d),1,Length(sVALUE_1)));
|
CheckEquals(sVALUE_1, Copy(TTimeRemotable.ToStr(d),1,Length(sVALUE_1)));
|
||||||
|
|
||||||
d := xsd_EncodeTime(12,34,56,0);
|
d := xsd_EncodeTime(12,34,56,0);
|
||||||
CheckEquals(sVALUE_2, Copy(TTimeRemotable.ToString(d),1,Length(sVALUE_2)));
|
CheckEquals(sVALUE_2, Copy(TTimeRemotable.ToStr(d),1,Length(sVALUE_2)));
|
||||||
|
|
||||||
d := xsd_EncodeTime(20,34,56,0);
|
d := xsd_EncodeTime(20,34,56,0);
|
||||||
CheckEquals(sVALUE_3, Copy(TTimeRemotable.ToString(d),1,Length(sVALUE_3)));
|
CheckEquals(sVALUE_3, Copy(TTimeRemotable.ToStr(d),1,Length(sVALUE_3)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTest_TTimeRemotable.Parse();
|
procedure TTest_TTimeRemotable.Parse();
|
||||||
|
@ -3006,7 +3006,7 @@ begin
|
|||||||
CheckEquals(Ord(teFour),Ord(a.ObjProp.Val_Enum));
|
CheckEquals(Ord(teFour),Ord(a.ObjProp.Val_Enum));
|
||||||
CheckEquals('456',a.ObjProp.Val_String);
|
CheckEquals('456',a.ObjProp.Val_String);
|
||||||
CheckEquals(WideString('wide456'),a.ObjProp.Val_WideString);
|
CheckEquals(WideString('wide456'),a.ObjProp.Val_WideString);
|
||||||
CheckEquals(TDateRemotable.FormatDate(DATE_VALUE),TDateRemotable.FormatDate(a.ObjProp.Val_Date.AsDate));
|
CheckEquals(TDateRemotable.ToStr(DATE_VALUE),TDateRemotable.ToStr(a.ObjProp.Val_Date.AsDate));
|
||||||
CheckEquals(TIME_VALUE,a.ObjProp.Val_Time.AsString);
|
CheckEquals(TIME_VALUE,a.ObjProp.Val_Time.AsString);
|
||||||
{$IFDEF WST_UNICODESTRING}
|
{$IFDEF WST_UNICODESTRING}
|
||||||
CheckEquals('unicode456',a.ObjProp.Val_UnicodeString);
|
CheckEquals('unicode456',a.ObjProp.Val_UnicodeString);
|
||||||
@ -4820,7 +4820,7 @@ begin
|
|||||||
CheckEquals(Ord(teFour),Ord(a.ObjProp.Val_Enum));
|
CheckEquals(Ord(teFour),Ord(a.ObjProp.Val_Enum));
|
||||||
CheckEquals('456',a.ObjProp.Val_String);
|
CheckEquals('456',a.ObjProp.Val_String);
|
||||||
CheckEquals(WideString('wide456'),a.ObjProp.Val_WideString);
|
CheckEquals(WideString('wide456'),a.ObjProp.Val_WideString);
|
||||||
CheckEquals(TDateRemotable.FormatDate(DATE_VALUE),TDateRemotable.FormatDate(a.ObjProp.Val_Date.AsDate));
|
CheckEquals(TDateRemotable.ToStr(DATE_VALUE),TDateRemotable.ToStr(a.ObjProp.Val_Date.AsDate));
|
||||||
{$IFDEF WST_UNICODESTRING}
|
{$IFDEF WST_UNICODESTRING}
|
||||||
CheckEquals('unicode456',a.ObjProp.Val_UnicodeString);
|
CheckEquals('unicode456',a.ObjProp.Val_UnicodeString);
|
||||||
{$ENDIF WST_UNICODESTRING}
|
{$ENDIF WST_UNICODESTRING}
|
||||||
|
Reference in New Issue
Block a user