Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
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
 
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 20-May-13 4:39am
Edited 10-Jun-13 5:55am
v2
Comments
Richard MacCutchan at 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 at 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 at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

That's was a problem with memory, zombie pointer
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 26 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100