Thread: CTimeSpan and CTime - are they machine specific?? pls help.

  1. #1
    Registered User intruder's Avatar
    Join Date
    Nov 2002
    Posts
    48

    Unhappy CTimeSpan and CTime - are they machine specific?? pls help.

    Hi all..

    i have a question.

    i am trying to calculate the date and doing some addition of time to the objects by using CTimeSpan and CTime.

    so my question is, are these classes machine specific?

    herez what i am doing.

    int ActualDayCount::nAddDays( Date& dtAddTo, int nDays )
    {
    CTimeSpan ctsSpan = CTimeSpan( nDays, 0, 0, 0 );
    CTime ctAddTo = dtAddTo.GetCTime();

    ctAddTo += ctsSpan;
    dtAddTo = Date( ctAddTo );
    }

    but what i have seen is it gives me difference results when i am running the code on a Server as compared to when i run the code in development with same input date and the nDays.

    any help will be highly appreciated.

    Thanks,
    In.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I've never heard of CTime or CTimeSpan. They aren't part of standard C++ (well, maybe Windows C++). My only guess is that perhaps on one compiler integers are smaller than on the other. How different are the results?

    Perhaps you could find the website for those classes and see if there are any portability issues for them.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User intruder's Avatar
    Join Date
    Nov 2002
    Posts
    48
    I am getting a diff of around one day.

    Thanks,
    In

  4. #4
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    CTime and CTimeSpan are MFC classes so yes, they are not portable (i.e. they will only work on windows).

    the boost.date_time library might be helpful to you.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    These are platform specific and compiler specific classes.
    Seems to be a very bad idea when trying to do portable code.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I am getting a diff of around one day.
    Leap year? I have no idea what could be wrong, as I've never heard of those classes.

    If you want portable time and date functions, try the functions in <ctime>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed