Click here to Skip to main content
15,895,827 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello!
I have the huge problem with COleDateTime and CTime.
That's like a hell, and I can't understand it. I try to initialize COleDateTime by value of CTime

C++
void CAnnouncementScheduleTab::ConvertToDateTime(COleDateTime & oleDate, CTime &time, CTime &date)
{
    oleDate.SetStatus(COleDateTime::valid);
    oleDate.SetDateTime(date.GetYear(), date.GetMonth(), date.GetDay(),
        time.GetHour(), time.GetMinute(), time.GetSecond());
    int a = date.GetYear();
    int b = date.GetMonth();
    int c = date.GetDay();
    int d = time.GetHour() ;
    int e = time.GetMinute();
    int f = time.GetSecond();

    int y = oleDate.GetYear();
    int h = oleDate.GetMonth();
    int m = oleDate.GetDay();
    int o = oleDate.GetHour();
    int l = oleDate.GetMinute();
    int p = oleDate.GetSecond();
    ASSERT(a == y && b == h
        && c == m && d == o &&
        e == l && f == p);

    oleDate.SetStatus(COleDateTime::valid);
}


How can you see time and date variables is OK! and a - f is normal values, but y-p is -1.
Why Am I getting it?
Before this method I did default constructor and sometimes I got bad values like a couple minutes more or less then I expected.
Thank you
Posted
Updated 10-Jun-13 4:55am
v2
Comments
Richard MacCutchan 20-May-13 10:53am    
You should check the return code of the call to oleDate.SetDateTime. You are assuming that it succeeds which is not the best way of writing code. Use your debugger to step through the code and check the values at each step.
thomas_wingfield 20-May-13 11:47am    
Hello Richard!Thanks for reply
I researched that if I would be initialize in constructor Current Time and after that give new values it will be ok
but I have another trouble. every time I get one-two minutes more or less.
Did you hear about it?I give correct value, but received 1-2 minutes more then I expect
Richard MacCutchan 20-May-13 13:12pm    
Sorry, I have not used these classes. I can only repeat my previous advice that you use your debugger to see what is going on. However, looking at the COleDateTime documentation I notice that it uses the fractional part of a floating point number to hold the time portion, which may account for the loss of precision.
nv3 10-Jun-13 11:32am    
Your code DID run correctly in my test environment. I would like to suggest that you do a test run with two known values for time and date and show what exactly you get for the variables a ...p and the double value that is used in COleDateTime. So we could reproduce your test case.

it looks like the oledate isnt valid.

Hint: it is a input parameter in your function, so make a valid oledate before you call your function.
 
Share this answer
 
That's was a problem with memory, zombie pointer
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900