« SoapStr2Datetime (rtl) » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
<source lang='delphi'>Function SoapStr2Datetime(const S:string):TDateTime;</source> | <source lang='delphi'>Function SoapStr2Datetime(const S:string):TDateTime;</source> | ||
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. | ||
|} | |} | ||
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> |
Version du 14 août 2009 à 08:57
<source lang='delphi'>Function SoapStr2Datetime(const S:string):TDateTime;</source>
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
<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
// 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; </source>
Voir aussi:
{{#if:Développement DSM|
{{#if:Développement DSM|— Développement DSM |}} — Développement DSM —
|
{{#if:|— [[{{{1}}}]] |}} — Développement DSM —
}}