mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-10 05:25:58 +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'
|
||||
else
|
||||
fmt := '%.2d''%.2d''';
|
||||
i := GetLocalTimeOffset(ADate); //min
|
||||
i := GetLocalTimeOffset(ADate, False); //min
|
||||
if i < 0 then
|
||||
Result := '+'
|
||||
else if i = 0 then begin
|
||||
|
@ -2257,7 +2257,7 @@ Var
|
||||
begin
|
||||
T:=aValue;
|
||||
if Not aInputisUTC then
|
||||
T:=IncMinute(T,GetLocalTimeOffset(AValue));
|
||||
T:=IncMinute(T,GetLocalTimeOffset(AValue, AInputisUTC));
|
||||
Result:=Round(DateTimeDiff(RecodeMillisecond(T,0),UnixEpoch)*SecsPerDay);
|
||||
end;
|
||||
|
||||
@ -2267,7 +2267,7 @@ Function UnixToDateTime(const AValue: Int64; aReturnUTC : Boolean = true): TDate
|
||||
begin
|
||||
Result:=IncSecond(UnixEpoch, AValue);
|
||||
if Not aReturnUTC then
|
||||
Result:=IncMinute(Result,-GetLocalTimeOffset(Result));
|
||||
Result:=IncMinute(Result,-GetLocalTimeOffset(Result, True));
|
||||
end;
|
||||
|
||||
|
||||
@ -2668,7 +2668,7 @@ end;
|
||||
function UniversalTimeToLocal(UT: TDateTime): TDateTime;
|
||||
|
||||
begin
|
||||
Result:=SysUtils.UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT));
|
||||
Result:=SysUtils.UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT, True));
|
||||
end;
|
||||
|
||||
function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
|
||||
@ -2680,7 +2680,7 @@ end;
|
||||
Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
|
||||
|
||||
begin
|
||||
Result:=SysUtils.LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT));
|
||||
Result:=SysUtils.LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT, False));
|
||||
end;
|
||||
|
||||
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: Integer): TDateTime;
|
||||
@ -2703,7 +2703,7 @@ var
|
||||
Offset: Integer;
|
||||
begin
|
||||
Result := FormatDateTime(FmtUTC, ADate);
|
||||
Offset := GetLocalTimeOffset(ADate);
|
||||
Offset := GetLocalTimeOffset(ADate, AInputIsUTC);
|
||||
if AInputIsUTC or (Offset=0) then
|
||||
Result:=Result+'Z'
|
||||
else
|
||||
@ -2929,7 +2929,7 @@ begin
|
||||
if ReturnUTC then
|
||||
Offset:=0
|
||||
else
|
||||
OffSet:=-GetLocalTimeOffset(ADateTime);
|
||||
OffSet:=-GetLocalTimeOffset(ADateTime, True);
|
||||
aDateTime:=IncMinute(aDateTime,Offset);
|
||||
Result:=True;
|
||||
end;
|
||||
|
@ -1525,15 +1525,15 @@ begin
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||
begin
|
||||
Result:=False;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime): Integer;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean): Integer;
|
||||
begin
|
||||
if not GetLocalTimeOffset(DateTime, Result) then
|
||||
if not GetLocalTimeOffset(DateTime, InputIsUTC, Result) then
|
||||
Result:=GetLocalTimeOffset();
|
||||
end;
|
||||
|
||||
@ -1542,7 +1542,7 @@ end;
|
||||
function UniversalTimeToLocal(UT: TDateTime): TDateTime;
|
||||
|
||||
begin
|
||||
Result:=UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT));
|
||||
Result:=UniversalTimeToLocal(UT,-GetLocalTimeOffset(UT, True));
|
||||
end;
|
||||
|
||||
function UniversalTimeToLocal(UT: TDateTime; TZOffset : Integer): TDateTime;
|
||||
@ -1559,7 +1559,7 @@ end;
|
||||
Function LocalTimeToUniversal(LT: TDateTime): TDateTime;
|
||||
|
||||
begin
|
||||
Result:=LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT));
|
||||
Result:=LocalTimeToUniversal(LT,-GetLocalTimeOffset(LT, False));
|
||||
end;
|
||||
|
||||
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;
|
||||
|
||||
function GetLocalTimeOffset: Integer;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime): Integer;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean = False): Integer;
|
||||
|
||||
Function FileDateToUTC (Filedate : Int64) : TDateTime;
|
||||
|
||||
|
@ -1620,7 +1620,7 @@ begin
|
||||
Result := -Tzseconds div 60;
|
||||
end;
|
||||
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||
|
||||
var
|
||||
Year, Month, Day, Hour, Minute, Second, MilliSecond: word;
|
||||
@ -1629,7 +1629,10 @@ var
|
||||
begin
|
||||
DecodeDate(DateTime, Year, Month, Day);
|
||||
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 }
|
||||
if (Tzinfo.validsince<UnixTime) and (UnixTime<Tzinfo.validuntil) then
|
||||
begin
|
||||
|
@ -832,7 +832,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; out Offset: Integer): Boolean;
|
||||
function GetLocalTimeOffset(const DateTime: TDateTime; const InputIsUTC: Boolean; out Offset: Integer): Boolean;
|
||||
var
|
||||
Year: Integer;
|
||||
const
|
||||
@ -884,8 +884,14 @@ begin
|
||||
|
||||
if (TZInfo.StandardDate.Month>0) and (TZInfo.DaylightDate.Month>0) then
|
||||
begin // there is DST
|
||||
// DaylightDate and StandardDate are local times
|
||||
DSTStart := RelWeekDayToDateTime(TZInfo.DaylightDate);
|
||||
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
|
||||
Offset := TZInfo.Bias+TZInfo.DaylightBias
|
||||
else
|
||||
|
@ -460,7 +460,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;
|
||||
|
||||
begin
|
||||
Result := False; // not supported
|
||||
|
Loading…
Reference in New Issue
Block a user