🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #486

Re: time.h bug?

#486
From: Bob Gonder
Date: Fri, 14 Mar 2008 17:25
48 lines
2376 bytes
dave_c wrote:

>When executing this code in Borland C++Builder 6 and Codegear C++Builder
>  2007 I get different results:
>
>C++Builder 6:
>14:24:40 (1205501080) dst=0
>
>C++Builder 2007:
>14:24:40 (1205497480) dst=1

The values you show are the same.
Only difference is the DST adjustment.

Just guessing here...
When BCB6 was written, DST started in April.
RAD2007 has been patched to understand that DST started
last week, and may change on the whim of the powers that be.

>So the result (in local time) is the same, but I'm using the value from
>time(0) (which in this case is 1205501080 or 1205497480) to do
>calculations compared to a time I receive from an external DLL. in
>C++Builder 6 the time calculation was correct, but in C++ Builder 2007 I
>get calculation errors of 3600 seconds.

If you want to compare the times, use a time comparison
function, or manually adjust using the tm_isdst flag.

   long t1 = time(0);
   long t2 = DLLtime();

   long diff1 = difftime( t1, t2 );


#define ADJUST( t ) (t.tm_isdst>0?3600:0)

   long t1 = time(0);
   long t2 = DLLtime();
   struct tm ptime1 = *localtime(&t1);
   struct tm ptime2 = *localtime(&t2);

   long diff2 = (t1-ADJUST(time1)) - (t2-ADJUST(time2)) ;

>It seems that the time(0) function in C++Builder 2007 seems to return
>the local time, instead of the GMT time?

No, localtime(&t) returns local time.
Try gmtime(&t)
Technical Details
Message-ID: <jhblt3t6kp90stncp3ogi5oumjj3le4ug1@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <47da8d4e$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,63bca7d4c872a25f
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: time.h bug?
Date: Fri, 14 Mar 2008 10:25:57 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <jhblt3t6kp90stncp3ogi5oumjj3le4ug1@4ax.com>
References: <47da8d4e$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.145.47
X-Trace: newsgroups.borland.com 1205515553 67.77.145.47 (14 Mar 2008 10:25:53 -0700)
Lines: 50
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail