Question

I'm using CTime and CTimeSpan and doing simple arithmetic with it. At some point I'm doing something like

...
CTime someTime;
CTimeSpan oneDay(1,0,0,0);
return someTime + oneDay;

now if someTime is during daylight saving time and the return value is not (or vice versa) this operation adds 23 hours (or 25 hours respectively) which is absolutely correct. What I need anyway is that daylight saving is ignored entirely. I want the result to be the same time of the day as the date before the sum operation.

One way to solve this would be to check for those cases and correct the result accordingly. But I was wondering if there is a way to disable the daylight savings functionality altogether.

Was it helpful?

Solution

I ended up correcting it myself using CTime::GetLocalTm(...).

tm myTm;
original.GetLocalTm(&myTm);
BOOL bWasDST = (myTm.tm_isdst != 0);

result.GetLocalTm(&myTm);
BOOL bIsDST = (myTm.tm_isdst != 0);

if ((bWasDST - bIsDST) != 0)
{
    CTimeSpan dstCorrection(0, bWasDST - bIsDST, 0, 0);
    result += dstCorrection;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top