This goes against all reasonnable logic but when I try to construct a CTime containing '2' for hours, it will return a 1 instead of 2 in the hour field. Only for this hour value. Platform is WindowsCE 6.0, plain c++ (VS2005)
void main(void)
{
CTime myTime;
int myMonth;
for(myMonth=1; myMonth < 13; myMonth++)
{
myTime = CTime(2017, 03, 12, myMonth, 0, 0, 0);
printf("Month: %d", myMonth);
printf("\r");
printf("CTime: %d, %d, %d, %d, %d, %d", myTime.GetYear(), myTime.GetMonth(), myTime.GetDay(), myTime.GetHour(), myTime.GetMinute(), myTime.GetSecond());
printf("\r");
}
}
Month: 1
CTime: 2017, 3, 12, 1, 0, 0
Month: 2
CTime: 2017, 3, 12, 1, 0, 0 // !!!
Month: 3
CTime: 2017, 3, 12, 3, 0, 0
Month: 4
CTime: 2017, 3, 12, 4, 0, 0
Month: 5
CTime: 2017, 3, 12, 5, 0, 0
Month: 6
CTime: 2017, 3, 12, 6, 0, 0
Month: 7
CTime: 2017, 3, 12, 7, 0, 0
Month: 8
CTime: 2017, 3, 12, 8, 0, 0
Month: 9
CTime: 2017, 3, 12, 9, 0, 0
Month: 10
CTime: 2017, 3, 12, 10, 0, 0
Month: 11
CTime: 2017, 3, 12, 11, 0, 0
Month: 12
CTime: 2017, 3, 12, 12, 0, 0
Adding minutes and seconds works but still, hour is not good.
nDST can be -1, 0 or 1, or omitted (-1 by constructor default) it won't change anything, hour will still be put to 1 if entered at 2.
Quite frustrating.
Also, i tried something else:
CTime myCurrentTime = CTime::GetCurrentTime();
And guess what ? If it is indeed 2am, this constructor works correctly and put '2' in the hours.
-> I am currently scanning a DST transition table i built and I need to construct a time reference to it compare against current time and decide if i take the current entry in my table or i skip to the next.
Using any external addon libraries is not a solution because of memory footprint. I'm stucked with CE 6.0 and the board it was designed on 10 years ago. It would be nice to have a 'vanilla' c++ solution.
From the documentation:
On the night of the 12th March 2017, as the clock hits 2am, DST kicks in and your clock actually goes back to 1am. The function is interpreting your input as 2am winter time (because it doesn't know whether you mean DST or not, but has to pick one somehow!), but when you go to
GetHour()
the hour component of the resulting date, it's now 1am ... because you're in summer time.This is why working in local times is a nightmare! Try to find a UTC alternative if you can. Standard C++ has some quite nice time handling functions that you may be able to use instead of proprietary Microsoft stuff.