Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Mar 2005 16:47:42 +0300
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Ganbold <ganbold@micom.mng.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: subtracting days from localtime problem
Message-ID:  <20050331134742.GA600@pm514-9.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <6.2.0.14.2.20050331203318.031f2050@202.179.0.80>
References:  <6.2.0.14.2.20050331203318.031f2050@202.179.0.80>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Mar 31, 2005 at 08:53:12PM +0900, Ganbold wrote:

> I have problem subtracting days from current date using test program.
> We have daylight saving occured on 2AM of March 26, 2005.
> As you can see below, there is missing March 26th line from program output.
> And all lines after 27th March are wrong.
> Instead of 25th March it should be 26th March, 24th March should be 25th 
> March and so on.
> 
> Can somebody tell me why is this happening? How can I correct this
>  problem?

The problem is in tm_isdst field, which is 1, for current day
March 31.  You can see the problem in action, if you output not only
date, but also time and tm_isdst for new date.

To fix this problem set tm_isdst to -1 before mktime() function call,
and again output date together with time and see difference.  You can
set tm_isdst to 0 and see the difference, and carefully read documentation
for tm_isdst in SUSv3, for example.

If you want to do such manipulations with time using standard
library functions, then it will not be very easy, because of TZ
changes, the problem you got is only one of many.

ps: comp.unix.programmer would be a better place for such questions.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050331134742.GA600>