Validating time

This is a discussion on Validating time within the C++ Programming forums, part of the General Programming Boards category; Is there such a type as "days"?...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Is there such a type as "days"?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    Is there such a type as "days"?
    Yep! Got it to compile now... One issue though, Is this function accurate? I mean should return_days calculation consider hours and minutes as well?

    Code:
    void Contract::CalculateNoOfDays(Date issue_dt, Date return_dt)
    {
    	using namespace boost::gregorian;
    
    	std::ostringstream issue_dymonyr, return_dymonyr;
    
    	issue_dymonyr << issue_dt.getMonth() << "-" << issue_dt.getDay() << "-" << issue_dt.getYear();
    	return_dymonyr << return_dt.getMonth() << "-" << return_dt.getDay() << "-" << return_dt.getYear();
    	
    	try {
    	  date issuedDate(from_simple_string(issue_dymonyr.str()));
    	  date returnDate(from_simple_string(return_dymonyr.str()));
    	  days rental_days = returnDate - issuedDate;
    	}
    	catch(...) {
    		std::cout << "Bad date entered: " << issue_dymonyr.str() << return_dymonyr.str() << std::endl;
    	}
    }
    [EDIT}
    Not forgetting how to convert from days to a normal integer value [/EDIT]

  3. #18
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by csonx_p View Post
    Yep! Got it to compile now... One issue though, Is this function accurate? I mean should return_days calculation consider hours and minutes as well?

    Code:
    void Contract::CalculateNoOfDays(Date issue_dt, Date return_dt)
    {
    	using namespace boost::gregorian;
    
    	std::ostringstream issue_dymonyr, return_dymonyr;
    
    	issue_dymonyr << issue_dt.getMonth() << "-" << issue_dt.getDay() << "-" << issue_dt.getYear();
    	return_dymonyr << return_dt.getMonth() << "-" << return_dt.getDay() << "-" << return_dt.getYear();
    	
    	try {
    	  date issuedDate(from_simple_string(issue_dymonyr.str()));
    	  date returnDate(from_simple_string(return_dymonyr.str()));
    	  days rental_days = returnDate - issuedDate;
    	}
    	catch(...) {
    		std::cout << "Bad date entered: " << issue_dymonyr.str() << return_dymonyr.str() << std::endl;
    	}
    }
    [EDIT}
    Not forgetting how to convert from days to a normal integer value [/EDIT]
    this seems to compile

    Code:
    int  contractDays = rental_days.days();
    Still worried about if the results are accurate since hours and minutes are not explicitly specified...

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Maybe you want to take a look at the examples?
    http://www.boost.org/doc/libs/1_37_0...te_period_calc
    They might give you some insight. Be sure to consult the documentation for the classes, as well. There might be something there.

    I am not familiar with Boost::DateTime, however, so I cannot say.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Replies: 11
    Last Post: 03-29-2009, 01:27 PM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 07:17 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21