mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-11 16:55:52 +02:00
* Patch from Bruno Fierens to take into account milliseconds in RFC3339 dates
This commit is contained in:
parent
6597c81be0
commit
cff01fce48
@ -2420,14 +2420,14 @@ Function TryRFC3339ToDateTime(const Avalue: String; out ADateTime: TDateTime): B
|
|||||||
// yyyy-mm-ddThh:nn:ss.zzz
|
// yyyy-mm-ddThh:nn:ss.zzz
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TPartPos = (ppTime,ppYear,ppMonth,ppDay,ppHour,ppMinute,ppSec);
|
TPartPos = (ppTime,ppYear,ppMonth,ppDay,ppHour,ppMinute,ppSec,ppMSec);
|
||||||
TPos = Array [TPartPos] of byte;
|
TPos = Array [TPartPos] of byte;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
P : TPos = (11,1,6,9,12,15,18);
|
P : TPos = (11,1,6,9,12,15,18,21);
|
||||||
|
|
||||||
var
|
var
|
||||||
lY, lM, lD, lH, lMi, lS: Integer;
|
lY, lM, lD, lH, lMi, lS, lMs: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Trim(AValue) = '' then
|
if Trim(AValue) = '' then
|
||||||
@ -2443,14 +2443,18 @@ begin
|
|||||||
lH:=StrToIntDef(Copy(AValue,P[ppHour],2),-1);
|
lH:=StrToIntDef(Copy(AValue,P[ppHour],2),-1);
|
||||||
lMi:=StrToIntDef(Copy(AValue,P[ppMinute],2),-1);
|
lMi:=StrToIntDef(Copy(AValue,P[ppMinute],2),-1);
|
||||||
lS:=StrToIntDef(Copy(AValue,P[ppSec],2),-1);
|
lS:=StrToIntDef(Copy(AValue,P[ppSec],2),-1);
|
||||||
|
|
||||||
|
if (Length(AValue)>=P[ppMSec]) then
|
||||||
|
lmS := StrToIntDef(Copy(AValue,P[ppMSec],3),-1);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
lH:=0;
|
lH:=0;
|
||||||
lMi:=0;
|
lMi:=0;
|
||||||
lS:=0;
|
lS:=0;
|
||||||
|
lMS:=0;
|
||||||
end;
|
end;
|
||||||
Result:=(lY>=0) and (lM>=0) and (lD>=0) and (lH>=0) and (lMi>=0) and (ls>=0);
|
Result:=(lY>=0) and (lM>=0) and (lD>=0) and (lH>=0) and (lMi>=0) and (ls>=0) and (lMS>=0);
|
||||||
if Not Result then
|
if Not Result then
|
||||||
ADateTime:=0
|
ADateTime:=0
|
||||||
else
|
else
|
||||||
@ -2458,7 +2462,7 @@ begin
|
|||||||
if (lY = 0) or (lM = 0) or (lD = 0) then
|
if (lY = 0) or (lM = 0) or (lD = 0) then
|
||||||
ADateTime:=EncodeTime(lH, lMi, lS, 0)
|
ADateTime:=EncodeTime(lH, lMi, lS, 0)
|
||||||
else
|
else
|
||||||
ADateTime:=EncodeDate(lY, lM, lD) + EncodeTime(lH, lMi, lS, 0);
|
ADateTime:=EncodeDate(lY, lM, lD) + EncodeTime(lH, lMi, lS, lMs);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function RFC3339ToDateTime(const Avalue: String): TDateTime;
|
Function RFC3339ToDateTime(const Avalue: String): TDateTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user