[fpc-devel] New functions for time zone
Mark Morgan Lloyd
markMLl.fpc-devel at telemetry.co.uk
Wed Jul 11 15:06:17 CEST 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;
Are there already cases where a TDateTime is used as an interval rather
than for its original purpose? If not then I'd suggest that a new type
is in order, taking a leaf from the book of at least some SQL
implementations which have distinct timestamp and interval types.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-devel
mailing list