[fpc-devel] New functions for time zone
LacaK
lacak at zoznam.sk
Thu Jul 12 07:58:23 CEST 2012
Michael Van Canneyt wrote / napĂsal(a):
>
>
> On Wed, 11 Jul 2012, LacaK wrote:
>
>> Hi *,
>> I noticed, that there was just added new functions for supporting TZ
>> in rev. 21865 and 21866
>> Now function GetLocalTimeOffset: Integer returns offset *in minutes*
>> and later in functions LocalTimeToUniversal and UniversalTimeToLocal
>> are used commands to transform it to TDateTime using EncodeTime.
>> (f.e. EncodeTime(TZOffset div 60, TZOffset mod 60, 0, 0))
>>
>> My idea is change function GetLocalTimeOffset: TDateTime to return
>> TDateTime (offset in fraction of days - native FPC datetime format)
>> i.e. current implementation + "Result := Result / MinsPerDay"
>> I think, that it will be useful, because in real applications we will
>> need on each usage transform minutes to use it in Datetime calculations.
>> (LocalDateTime := UTCDateTime - GetLocalTimeOffset;)
>>
>> Then functions LocalTimeToUniversal and UniversalTimeToLocal will be
>> simple addition or subtraction like:
>> function UniversalTimeToLocal(UT: TDateTime; TZOffset : TDateTime):
>> TDateTime;
>> begin
>> Result := UT - TZOffset;
>> end;
>>
>> What do you think? It will simplify all.
>
> There are 2 sides to this medal. The function returns a number of
> timezones;
> This is usually expressed as a number of hours and minutes (the OS
> returns it so). The result is in 'natural' units.
>
AFAIK f.e. GetTimeZoneInformation under Windows return bias in minutes
> Returning it as a timestamp - while useful by itself - seems rather odd.
>
May be, that I expressed it wrong
My proposal is like:
Windows:
function GetLocalTimeOffset: double; <--
591
592 var
593 TZInfo: TTimeZoneInformation;
594
595 begin
596 case GetTimeZoneInformation(TZInfo) of
597 TIME_ZONE_ID_UNKNOWN:
598 Result := TZInfo.Bias;
599 TIME_ZONE_ID_STANDARD:
600 Result := TZInfo.Bias + TZInfo.StandardBias;
601 TIME_ZONE_ID_DAYLIGHT:
602 Result := TZInfo.Bias + TZInfo.DaylightBias;
603 else
604 Result := 0;
605 end;
+ Result := Result / MinsPerDay;
606 end;
Unix:
function GetLocalTimeOffset: double; <--
1405
1406 begin
+ Result := -Tzseconds / SecsPerDay;
1408 end;
dateutil.inc:
function UniversalTimeToLocal(UT: TDateTime; TZOffset : double): TDateTime;
2467
2468 begin
Result := UT - TZOffset;
2476 end;
Function LocalTimeToUniversal(LT: TDateTime;TZOffset: double): TDateTime;
2485
2486 begin
Result := LT + TZOffset;
2494 end;
if TZOffset will be "day fraction" then we can simplyfy above mentioned
functions, or am I wrong ?
Thanks
-Laco.
More information about the fpc-devel
mailing list