Changeset 476 for Common


Ignore:
Timestamp:
Jul 13, 2015, 11:54:55 AM (9 years ago)
Author:
chronos
Message:
  • Fixed second fraction read from XML date time.
Location:
Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r434 r476  
    6464procedure ExecuteProgram(CommandLine: string);
    6565procedure FreeThenNil(var Obj);
     66function RemoveQuotes(Text: string): string;
    6667
    6768
     
    440441end;
    441442
     443function RemoveQuotes(Text: string): string;
     444begin
     445  Result := Text;
     446  if (Pos('"', Text) = 1) and (Text[Length(Text)] = '"') then
     447    Result := Copy(Text, 2, Length(Text) - 2);
     448end;
     449
     450
    442451initialization
    443452
  • Common/UXMLUtils.pas

    r468 r476  
    1414procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
    1515procedure WriteString(Node: TDOMNode; Name: string; Value: string);
     16procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime);
    1617function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
    1718function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean;
    1819function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
     20function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime;
    1921
    2022
     
    7274  Minute: Integer;
    7375  Second: Integer;
     76  SecondFraction: Double;
    7477  Millisecond: Integer;
    7578begin
     
    9497      if Pos('Z', XMLDateTime) > 0 then
    9598        LeftCutString(XMLDateTime, Part, 'Z');
    96       Millisecond := StrToInt(Part);
     99      SecondFraction := StrToFloat('0.' + Part);
     100      Millisecond := Trunc(SecondFraction * 1000);
    97101    end else begin
    98102      if Pos('+', XMLDateTime) > 0 then
     
    156160end;
    157161
     162procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime);
     163var
     164  NewNode: TDOMNode;
     165begin
     166  NewNode := Node.OwnerDocument.CreateElement(Name);
     167  NewNode.TextContent := DateTimeToXMLTime(Value);
     168  Node.AppendChild(NewNode);
     169end;
     170
    158171function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
    159172var
     
    186199end;
    187200
     201function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime
     202  ): TDateTime;
     203var
     204  NewNode: TDOMNode;
     205begin
     206  Result := DefaultValue;
     207  NewNode := Node.FindNode(Name);
     208  if Assigned(NewNode) then
     209    Result := XMLTimeToDateTime(NewNode.TextContent);
     210end;
     211
    188212end.
    189213
Note: See TracChangeset for help on using the changeset viewer.