mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 16:49:07 +02:00
* Fix bug #0033623, add parameters to UnixToDateTime/DateTimeTounix to return/accept UTC
git-svn-id: trunk@39444 -
This commit is contained in:
parent
0c6cf12fbf
commit
6568dea8a9
@ -409,8 +409,8 @@ Function TryModifiedJulianDateToDateTime(const AValue: Double; out ADateTime: TD
|
|||||||
Unix timestamp support.
|
Unix timestamp support.
|
||||||
---------------------------------------------------------------------}
|
---------------------------------------------------------------------}
|
||||||
|
|
||||||
Function DateTimeToUnix(const AValue: TDateTime): Int64;
|
Function DateTimeToUnix(const AValue: TDateTime; AInputIsUTC: Boolean = True): Int64;
|
||||||
Function UnixToDateTime(const AValue: Int64): TDateTime;
|
Function UnixToDateTime(const AValue: Int64; aReturnUTC : Boolean = true): TDateTime;
|
||||||
Function UnixTimeStampToMac(const AValue: Int64): Int64;
|
Function UnixTimeStampToMac(const AValue: Int64): Int64;
|
||||||
|
|
||||||
{ ---------------------------------------------------------------------
|
{ ---------------------------------------------------------------------
|
||||||
@ -2228,16 +2228,25 @@ end;
|
|||||||
Unix timestamp support.
|
Unix timestamp support.
|
||||||
---------------------------------------------------------------------}
|
---------------------------------------------------------------------}
|
||||||
|
|
||||||
Function DateTimeToUnix(const AValue: TDateTime): Int64;
|
Function DateTimeToUnix(const AValue: TDateTime; AInputIsUTC: Boolean = True): Int64;
|
||||||
|
|
||||||
|
Var
|
||||||
|
T : TDateTime;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=Round(DateTimeDiff(RecodeMillisecond(AValue,0),UnixEpoch)*SecsPerDay);
|
T:=aValue;
|
||||||
|
if Not aInputisUTC then
|
||||||
|
T:=IncMinute(T,GetLocalTimeOffset);
|
||||||
|
Result:=Round(DateTimeDiff(RecodeMillisecond(T,0),UnixEpoch)*SecsPerDay);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function UnixToDateTime(const AValue: Int64): TDateTime;
|
Function UnixToDateTime(const AValue: Int64; aReturnUTC : Boolean = true): TDateTime;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=IncSecond(UnixEpoch, AValue);
|
Result:=IncSecond(UnixEpoch, AValue);
|
||||||
|
if Not aReturnUTC then
|
||||||
|
Result:=IncMinute(Result,-GetLocalTimeOffset);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user