SoapStr2Datetime (rtl)

De Wiki1000
(Différences entre les versions)
 
 
(4 révisions intermédiaires par un utilisateur sont masquées)
Ligne 1 : Ligne 1 :
 
 
<source lang='delphi'>Function SoapStr2Datetime(const S:string):TDateTime;</source>
 
<source lang='delphi'>Function SoapStr2Datetime(const S:string):TDateTime;</source>
  
description
+
Cette fonction convertie une chaîne représentant une date et heure au format SOAP en date et heure.
  
 
{|class="wikitable"
 
{|class="wikitable"
 
|-
 
|-
 
|Result
 
|Result
|
+
|La date et heure représenté par la chaîne.
 
|-
 
|-
 
|S
 
|S
|
+
|Une chaîne représentant une date et heure au format SOAP.
|-
+
|Result
+
|
+
 
|}
 
|}
  
Ligne 19 : Ligne 15 :
  
 
<source lang='delphi'>
 
<source lang='delphi'>
 +
// Decode 1999-05-31T13:20:00.000-05:00 as datetime
 +
//
 +
function soapStr2Datetime(ss:string):TdateTime;
 +
var xx:Integer; sz,sd,st:string;
 
begin
 
begin
 +
  // ISO 8601
 +
  // http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#dateTime
 +
  // 2006-11-16T13:29:07.3389395+01:00
 +
  //
 +
  xx := Pos('T',ss);
 +
  if xx<>0 then
 +
  begin
 +
    sd := Copy(ss,1,xx-1);
 +
    st := Copy(ss,xx+1,length(ss)-xx);
 +
  end
 +
  else
 +
  if Pos(':',ss)<>0 then
 +
  begin
 +
    // only time
 +
    sd := '';
 +
    st := ss;
 +
  end
 +
  else
 +
  begin
 +
    // only date
 +
    sd := ss;
 +
    st := '';
 +
  end;
 +
  //
 +
  sz := '';
 +
  if (st<>'') then
 +
  begin
 +
      // Timezone part
 +
      xx := Pos('Z',st);
 +
      if xx<>0 then
 +
      begin
 +
        sz := 'Z';  //timezone part
 +
        st := Copy(st,1,xx-1);
 +
      end;
 +
    xx := Pos('-',st);
 +
    if xx<>0 then
 +
      begin
 +
        sz := Copy(st,xx,length(st)-xx+1);
 +
        st := Copy(st,1,xx-1);
 +
      end;
 +
    xx := Pos('+',st);
 +
    if xx<>0 then
 +
      begin
 +
        sz := Copy(st,xx,length(st)-xx+1);
 +
        st := Copy(st,1,xx-1);
 +
      end;
 +
  end;
 +
  // UTC Result
 +
  Result := soapStr2Date(sd)+soapStr2Time(st)-soapTimezone2Offset(sz);
 +
  //
 +
  if (st<>'')or(sz<>'') then Result := GetLocalTime(Result);
 
end;
 
end;
 
</source>
 
</source>
 +
 +
Alias de cette fonction :
 +
 +
* [[IsoToDatetime (rtl)|ISOToDatetime]]
  
 
Voir aussi:
 
Voir aussi:
 +
 +
* [[DateTime2SoapStr (rtl)|Datetime2SoapStr]]
 +
* [[DatetimeToISO (rtl)|DatetimeToISO]]
  
 
{{Footer|Développement DSM}}
 
{{Footer|Développement DSM}}
 
[[category:RTL Date et heure]]
 
[[category:RTL Date et heure]]

Version actuelle en date du 25 février 2014 à 14:30

Function SoapStr2Datetime(const S:string):TDateTime;

Cette fonction convertie une chaîne représentant une date et heure au format SOAP en date et heure.

Result La date et heure représenté par la chaîne.
S Une chaîne représentant une date et heure au format SOAP.

Exemple

// Decode 1999-05-31T13:20:00.000-05:00 as datetime
//
function soapStr2Datetime(ss:string):TdateTime;
var xx:Integer; sz,sd,st:string;
begin
  // ISO 8601
  // http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#dateTime
  // 2006-11-16T13:29:07.3389395+01:00
  //
  xx := Pos('T',ss);
  if xx<>0 then
   begin
     sd := Copy(ss,1,xx-1);
     st := Copy(ss,xx+1,length(ss)-xx);
   end
   else
  if Pos(':',ss)<>0 then
   begin
     // only time
     sd := '';
     st := ss;
   end
   else
   begin
     // only date
     sd := ss;
     st := '';
   end;
  //
  sz := '';
  if (st<>'') then
   begin
      // Timezone part
      xx := Pos('Z',st);
      if xx<>0 then
       begin
         sz := 'Z';  //timezone part
         st := Copy(st,1,xx-1);
       end;
     xx := Pos('-',st);
     if xx<>0 then
      begin
        sz := Copy(st,xx,length(st)-xx+1);
        st := Copy(st,1,xx-1);
      end;
     xx := Pos('+',st);
     if xx<>0 then
      begin
        sz := Copy(st,xx,length(st)-xx+1);
        st := Copy(st,1,xx-1);
      end;
   end;
  // UTC Result
  Result := soapStr2Date(sd)+soapStr2Time(st)-soapTimezone2Offset(sz);
  //
  if (st<>'')or(sz<>'') then Result := GetLocalTime(Result);
end;

Alias de cette fonction :

Voir aussi:

Développement DSMDéveloppement DSM





Whos here now:   Members 0   Guests 0   Bots & Crawlers 1
 
Outils personnels