mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 13:19:12 +02:00
GetLocalTimeOffset: add InputIsUTC parameter to DateTime-aware overloads
git-svn-id: trunk@47293 -
This commit is contained in:
parent
6df9ad8e50
commit
a02d676b06
@ -1294,7 +1294,7 @@ begin
|
|||||||
fmt := '%.2d:%.2d'
|
fmt := '%.2d:%.2d'
|
||||||
else
|
else
|
||||||
fmt := '%.2d''%.2d''';
|
fmt := '%.2d''%.2d''';
|
||||||
i := GetLocalTimeOffset(ADate); //min
|
i := GetLocalTimeOffset(ADate, False); //min
|
||||||
if i < 0 then
|
if i < 0 then
|
||||||
Result := '+'
|
Result := '+'
|
||||||
else if i = 0 then begin
|
else if i = 0 then begin
|
||||||
|
@ -2257,7 +2257,7 @@ Var
|
|||||||
begin
|
begin
|
||||||
T:=aValue;
|
T:=aValue;
|
||||||
if Not aInputisUTC then
|
if Not aInputisUTC then
|
||||||
T:=IncMinute(T,GetLocalTimeOffset(AValue));
|
T:=IncMinute(T,GetLocalTimeOffset(AValue, AInputisUTC));
|
||||||
Result:=Round(DateTimeDiff(RecodeMillisecond(T,0),UnixEpoch)*SecsPerDay);
|
Result:=Round(DateTimeDiff(RecodeMillisecond(T,0),UnixEpoch)*SecsPerDay);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2267,7 +2267,7 @@ Function UnixToDateTime(const AValue: Int64; aReturnUTC : Boolean = true): TDate
|
|||||||
begin
|
begin
|
||||||
Result:=IncSecond(UnixEpoch, AValue);
|
Result:=IncSecond(UnixEpoch, AValue);
|
||||||
if Not aReturnUTC then
|
if Not aReturnUTC then
|
||||||
Result:=IncMinute(Result,-GetLocalTimeOffset(Result));
|
Result:=IncMinute(Result,-GetLocalTimeOffset(Result, True));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -2668,7 +2668,7 @@ end;
|
|||||||
function UniversalTimeToLocal(UT: TDateTime): TDateTime;
|
function UniversalTimeToLocal(UT: TDateTime): TDateTime;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=SysUtils.UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT));
|
Result:=SysUtils.UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT, True));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
|
function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
|
||||||
@ -2680,7 +2680,7 @@ end;
|
|||||||
Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
|
Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=SysUtils.LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT));
|
Result:=SysUtils.LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT, False));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
|
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
|
||||||
@ -2703,7 +2703,7 @@ var
|
|||||||
Offset: Integer;
|
Offset: Integer;
|
||||||
begin
|
begin
|
||||||
Result := FormatDateTime(FmtUTC, ADate);
|
Result := FormatDateTime(FmtUTC, ADate);
|
||||||
Offset := GetLocalTimeOffset(ADate);
|
Offset := GetLocalTimeOffset(ADate, AInputIsUTC);
|
||||||
if AInputIsUTC or (Offset=0) then
|
if AInputIsUTC or (Offset=0) then
|
||||||
Result:=Result+'Z'
|
Result:=Result+'Z'
|
||||||
else
|
else
|
||||||
@ -2929,7 +2929,7 @@ begin
|
|||||||
if ReturnUTC then
|
if ReturnUTC then
|
||||||
Offset:=0
|
Offset:=0
|
||||||
else
|
else
|
||||||
OffSet:=-GetLocalTimeOffset(ADateTime);
|
OffSet:=-GetLocalTimeOffset(ADateTime, True);
|
||||||
aDateTime:=IncMinute(aDateTime,Offset);
|
aDateTime:=IncMinute(aDateTime,Offset);
|
||||||
Result:=True;
|
Result:=True;
|
||||||
end;
|
end;
|
||||||
|
@ -1525,15 +1525,15 @@ begin
|
|||||||
Result:=0;
|
Result:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
Result:=False;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime): Integer;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean): Integer;
|
||||||
begin
|
begin
|
||||||
if not GetLocalTimeOffset(DateTime, Result) then
|
if not GetLocalTimeOffset(DateTime, InputIsUTC, Result) then
|
||||||
Result:=GetLocalTimeOffset();
|
Result:=GetLocalTimeOffset();
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1542,7 +1542,7 @@ end;
|
|||||||
function UniversalTimeToLocal(UT: TDateTime): TDateTime;
|
function UniversalTimeToLocal(UT: TDateTime): TDateTime;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT));
|
Result:=UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT, True));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
|
function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
|
||||||
@ -1559,7 +1559,7 @@ end;
|
|||||||
Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
|
Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT));
|
Result:=LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT, False));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
|
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
|
||||||
|
@ -200,8 +200,8 @@ procedure ReplaceTime(var dati:TDateTime; NewTime : TDateTime); inline;
|
|||||||
procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime); inline;
|
procedure ReplaceDate(var DateTime: TDateTime; const NewDate: TDateTime); inline;
|
||||||
|
|
||||||
function GetLocalTimeOffset: Integer;
|
function GetLocalTimeOffset: Integer;
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime): Integer;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean = False): Integer;
|
||||||
|
|
||||||
Function FileDateToUTC (Filedate : Int64) : TDateTime;
|
Function FileDateToUTC (Filedate : Int64) : TDateTime;
|
||||||
|
|
||||||
|
@ -1620,7 +1620,7 @@ begin
|
|||||||
Result := -Tzseconds div 60;
|
Result := -Tzseconds div 60;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||||
|
|
||||||
var
|
var
|
||||||
Year, Month, Day, Hour, Minute, Second, MilliSecond: word;
|
Year, Month, Day, Hour, Minute, Second, MilliSecond: word;
|
||||||
@ -1629,7 +1629,10 @@ var
|
|||||||
begin
|
begin
|
||||||
DecodeDate(DateTime, Year, Month, Day);
|
DecodeDate(DateTime, Year, Month, Day);
|
||||||
DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
|
DecodeTime(DateTime, Hour, Minute, Second, MilliSecond);
|
||||||
UnixTime:=LocalToEpoch(Year, Month, Day, Hour, Minute, Second);
|
if InputIsUTC then
|
||||||
|
UnixTime:=UniversalToEpoch(Year, Month, Day, Hour, Minute, Second)
|
||||||
|
else
|
||||||
|
UnixTime:=LocalToEpoch(Year, Month, Day, Hour, Minute, Second);
|
||||||
{ check if time is in current global Tzinfo }
|
{ check if time is in current global Tzinfo }
|
||||||
if (Tzinfo.validsince<UnixTime) and (UnixTime<Tzinfo.validuntil) then
|
if (Tzinfo.validsince<UnixTime) and (UnixTime<Tzinfo.validuntil) then
|
||||||
begin
|
begin
|
||||||
|
@ -832,7 +832,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||||
var
|
var
|
||||||
Year: Integer;
|
Year: Integer;
|
||||||
const
|
const
|
||||||
@ -884,8 +884,14 @@ begin
|
|||||||
|
|
||||||
if (TZInfo.StandardDate.Month>0) and (TZInfo.DaylightDate.Month>0) then
|
if (TZInfo.StandardDate.Month>0) and (TZInfo.DaylightDate.Month>0) then
|
||||||
begin // there is DST
|
begin // there is DST
|
||||||
|
// DaylightDate and StandardDate are local times
|
||||||
DSTStart := RelWeekDayToDateTime(TZInfo.DaylightDate);
|
DSTStart := RelWeekDayToDateTime(TZInfo.DaylightDate);
|
||||||
DSTEnd := RelWeekDayToDateTime(TZInfo.StandardDate);
|
DSTEnd := RelWeekDayToDateTime(TZInfo.StandardDate);
|
||||||
|
if InputIsUTC then
|
||||||
|
begin
|
||||||
|
DSTStart := DSTStart + (TZInfo.Bias+TZInfo.StandardBias)/MinsPerDay;
|
||||||
|
DSTEnd := DSTEnd + (TZInfo.Bias+TZInfo.DaylightBias)/MinsPerDay;
|
||||||
|
end;
|
||||||
if (DateTime>DSTStart) and (DateTime<DSTEnd) then
|
if (DateTime>DSTStart) and (DateTime<DSTEnd) then
|
||||||
Offset := TZInfo.Bias+TZInfo.DaylightBias
|
Offset := TZInfo.Bias+TZInfo.DaylightBias
|
||||||
else
|
else
|
||||||
|
@ -460,7 +460,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result := False; // not supported
|
Result := False; // not supported
|
||||||
|
Loading…
Reference in New Issue
Block a user