[fpc-devel] New functions for time zone

Michael Van Canneyt michael at freepascal.org
Wed Jul 11 15:09:41 CEST 2012

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.

Returning it as a timestamp - while useful by itself - seems rather odd.

I'm also not quite sure what should be returned for negative values of the timezone info.
'today 23:00' or "Yesterday 23:00"

I think it should remain as it is, but if you want, we can create an extra 
function 'LocalTimeOffset' in DateUtils that returns the same thing as a 
TDateTime. This new function can then be used in conversion routines.


More information about the fpc-devel mailing list