Ignore:
Timestamp:
Jun 29, 2018, 11:44:07 PM (6 years ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Modified: Updated IPTV prices.
  • Added: deb package build script.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UXMLUtils.pas

    r89 r122  
    77uses
    88  {$IFDEF WINDOWS}Windows,{$ENDIF}
    9   Classes, SysUtils, DateUtils;
     9  Classes, SysUtils, DateUtils, DOM;
    1010
    1111function XMLTimeToDateTime(XMLDateTime: string): TDateTime;
    12 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;
     12function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;
     13procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer);
     14procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64);
     15procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
     16procedure WriteString(Node: TDOMNode; Name: string; Value: string);
     17procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime);
     18function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
     19function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64;
     20function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean;
     21function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
     22function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime): TDateTime;
    1323
    1424
     
    2030  TimeZoneInfo: TTimeZoneInformation;
    2131begin
     32  {$push}{$warn 5057 off}
    2233  case GetTimeZoneInformation(TimeZoneInfo) of
    23   TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;
    24   TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;
     34    TIME_ZONE_ID_STANDARD: Result := TimeZoneInfo.Bias + TimeZoneInfo.StandardBias;
     35    TIME_ZONE_ID_DAYLIGHT: Result := TimeZoneInfo.Bias + TimeZoneInfo.DaylightBias;
    2536  else
    2637    Result := 0;
    2738  end;
     39  {$pop}
    2840end;
    2941{$ELSE}
     
    3547function LeftCutString(var Source: string; out Output: string; Delimiter: string; Allowed: string = ''): Boolean;
    3648var
    37   I, J: Integer;
     49  I: Integer;
    3850  Matched: Boolean;
    3951begin
     
    6678  Minute: Integer;
    6779  Second: Integer;
     80  SecondFraction: Double;
    6881  Millisecond: Integer;
    6982begin
     
    88101      if Pos('Z', XMLDateTime) > 0 then
    89102        LeftCutString(XMLDateTime, Part, 'Z');
    90       Millisecond := StrToInt(Part);
     103      SecondFraction := StrToFloat('0' + DefaultFormatSettings.DecimalSeparator + Part);
     104      Millisecond := Trunc(SecondFraction * 1000);
    91105    end else begin
    92106      if Pos('+', XMLDateTime) > 0 then
     
    106120end;
    107121
    108 function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): WideString;
     122function DateTimeToXMLTime(Value: TDateTime; ApplyLocalBias: Boolean = True): string;
    109123const
    110124  Neg: array[Boolean] of string =  ('+', '-');
     
    123137end;
    124138
     139procedure WriteInteger(Node: TDOMNode; Name: string; Value: Integer);
     140var
     141  NewNode: TDOMNode;
     142begin
     143  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     144  NewNode.TextContent := DOMString(IntToStr(Value));
     145  Node.AppendChild(NewNode);
     146end;
     147
     148procedure WriteInt64(Node: TDOMNode; Name: string; Value: Int64);
     149var
     150  NewNode: TDOMNode;
     151begin
     152  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     153  NewNode.TextContent := DOMString(IntToStr(Value));
     154  Node.AppendChild(NewNode);
     155end;
     156
     157procedure WriteBoolean(Node: TDOMNode; Name: string; Value: Boolean);
     158var
     159  NewNode: TDOMNode;
     160begin
     161  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     162  NewNode.TextContent := DOMString(BoolToStr(Value));
     163  Node.AppendChild(NewNode);
     164end;
     165
     166procedure WriteString(Node: TDOMNode; Name: string; Value: string);
     167var
     168  NewNode: TDOMNode;
     169begin
     170  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     171  NewNode.TextContent := DOMString(Value);
     172  Node.AppendChild(NewNode);
     173end;
     174
     175procedure WriteDateTime(Node: TDOMNode; Name: string; Value: TDateTime);
     176var
     177  NewNode: TDOMNode;
     178begin
     179  NewNode := Node.OwnerDocument.CreateElement(DOMString(Name));
     180  NewNode.TextContent := DOMString(DateTimeToXMLTime(Value));
     181  Node.AppendChild(NewNode);
     182end;
     183
     184function ReadInteger(Node: TDOMNode; Name: string; DefaultValue: Integer): Integer;
     185var
     186  NewNode: TDOMNode;
     187begin
     188  Result := DefaultValue;
     189  NewNode := Node.FindNode(DOMString(Name));
     190  if Assigned(NewNode) then
     191    Result := StrToInt(string(NewNode.TextContent));
     192end;
     193
     194function ReadInt64(Node: TDOMNode; Name: string; DefaultValue: Int64): Int64;
     195var
     196  NewNode: TDOMNode;
     197begin
     198  Result := DefaultValue;
     199  NewNode := Node.FindNode(DOMString(Name));
     200  if Assigned(NewNode) then
     201    Result := StrToInt64(string(NewNode.TextContent));
     202end;
     203
     204function ReadBoolean(Node: TDOMNode; Name: string; DefaultValue: Boolean): Boolean;
     205var
     206  NewNode: TDOMNode;
     207begin
     208  Result := DefaultValue;
     209  NewNode := Node.FindNode(DOMString(Name));
     210  if Assigned(NewNode) then
     211    Result := StrToBool(string(NewNode.TextContent));
     212end;
     213
     214function ReadString(Node: TDOMNode; Name: string; DefaultValue: string): string;
     215var
     216  NewNode: TDOMNode;
     217begin
     218  Result := DefaultValue;
     219  NewNode := Node.FindNode(DOMString(Name));
     220  if Assigned(NewNode) then
     221    Result := string(NewNode.TextContent);
     222end;
     223
     224function ReadDateTime(Node: TDOMNode; Name: string; DefaultValue: TDateTime
     225  ): TDateTime;
     226var
     227  NewNode: TDOMNode;
     228begin
     229  Result := DefaultValue;
     230  NewNode := Node.FindNode(DOMString(Name));
     231  if Assigned(NewNode) then
     232    Result := XMLTimeToDateTime(string(NewNode.TextContent));
     233end;
     234
    125235end.
    126236
Note: See TracChangeset for help on using the changeset viewer.