Article View: news.software.readers
Article #239761Re: Pieter Zijlstra, may I see the code you use to create your Date line ?
From: Pieter Zijlstra
Date: Sun, 21 Feb 2010 21:10
Date: Sun, 21 Feb 2010 21:10
77 lines
3635 bytes
3635 bytes
JeffRelf.F-M.FM @. wrote:
>
>Pieter Zijlstra, may I see the code you use to create your Date line* ?
>*: “ Date: Thu, 11 Feb 2010 23:25:42 +0100 ”.
It is using LocalDateTimeToGMT(Now) ...
function OffsetFromUTC: TDateTime;
var
iBias: Integer;
tmez: TTimeZoneInformation;
begin
case GetTimeZoneInformation(tmez) of
TIME_ZONE_ID_INVALID :
raise EIdFailedToRetreiveTimeZoneInfo.Create(RSFailedTimeZoneInfo);
TIME_ZONE_ID_UNKNOWN :
iBias := tmez.Bias;
TIME_ZONE_ID_DAYLIGHT :
iBias := tmez.Bias + tmez.DaylightBias;
TIME_ZONE_ID_STANDARD :
iBias := tmez.Bias + tmez.StandardBias;
else
begin
raise EIdFailedToRetreiveTimeZoneInfo.Create(RSFailedTimeZoneInfo);
end;
end;
{We use ABS because EncodeTime will only accept positive values}
Result := EncodeTime(Abs(iBias) div 60, Abs(iBias) mod 60, 0, 0);
{The GetTimeZone function returns values oriented towards converting
a GMT time into a local time. We wish to do the opposite by returning
the difference between the local time and GMT. So I just make a positive
value negative and leave a negative value as positive}
if iBias > 0 then begin
Result := 0.0 - Result;
end;
end;
function UTCOffsetToStr(const AOffset: TDateTime; const AUseGMTStr:
Boolean = False): string;
var
AHour, AMin, ASec, AMSec: Word;
begin
if (AOffset = 0.0) and AUseGMTStr then
begin
Result := 'GMT'; {do not localize}
end else
begin
DecodeTime(AOffset, AHour, AMin, ASec, AMSec);
Result := Format(' %0.2d%0.2d', [AHour, AMin]); {do not localize}
if AOffset < 0.0 then begin
Result[1] := '-'; {do not localize}
end else begin
Result[1] := '+'; {do not localize}
end;
end;
end;
function LocalDateTimeToGMT(const Value: TDateTime; const AUseGMTStr:
Boolean = False) : String;
var
wDay, wMonth, wYear: Word;
begin
DecodeDate(Value, wYear, wMonth, wDay);
Result := Format('%s, %d %s %d %s %s',
[wdays[DayOfWeek(Value)], wDay, monthnames[wMonth],
wYear, FormatDateTime('HH":"nn":"ss', Value),
UTCOffsetToStr(OffsetFromUTC, AUseGMTStr)]);
end;
--
Pieter
"When the rich think about the poor, they have poor ideas."
-- Evita Peron
Technical Details
Message-ID:
<xn0gqo0982j61zm000@newszilla.xs4all.nl>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post2.news.xs4all.nl!newszilla.xs4all.nl!not-for-mailReferences:
<7tg6rlF9dpU1@mid.individual.net> <hl0t6i$jr8$1@news.eternal-september.org> <7tieq6FovvU1@mid.individual.net> <JeffRelf.F-M.FM.0O@2010_Feb11.6.58am> <xn0gqa0j92oqzta005@newszilla.xs4all.nl> <JeffRelf.F-M.FM.52@2010_Feb11.3.43pm> <JeffRelf.F-M.FM.vp@2010_Feb21.8.00am>Show Full Headers
Complete Article Headers
Message-ID: <xn0gqo0982j61zm000@newszilla.xs4all.nl> Subject: Re: Pieter Zijlstra, may I see the code you use to create your Date line ? Date: Sun, 21 Feb 2010 22:10:25 +0100 From: "Pieter Zijlstra" <p.zylstra.notthis@hccnet.nl> References: <7tg6rlF9dpU1@mid.individual.net> <hl0t6i$jr8$1@news.eternal-september.org> <7tieq6FovvU1@mid.individual.net> <JeffRelf.F-M.FM.0O@2010_Feb11.6.58am> <xn0gqa0j92oqzta005@newszilla.xs4all.nl> <JeffRelf.F-M.FM.52@2010_Feb11.3.43pm> <JeffRelf.F-M.FM.vp@2010_Feb21.8.00am> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post2.news.xs4all.nl!newszilla.xs4all.nl!not-for-mail Newsgroups: alt.free.newsservers,news.software.readers User-Agent: XanaNews/1.19.1.279 X-Ref: newszilla.xs4all.nl ~XNS:00001D63 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Lines: 77 NNTP-Posting-Host: 80.100.173.199 X-Trace: 1266786629 dreader28.news.xs4all.nl 4516 [::ffff:80.100.173.199]:15837