Example #1
0
/** Sets the date and time using a boost::posix_time::ptime
 *
 * @param _ptime :: boost::posix_time::ptime date and time.
 */
void DateAndTime::set_from_ptime(boost::posix_time::ptime _ptime) {
  if (_ptime.is_special()) {
    // --- SPECIAL VALUES! ----
    if (_ptime.is_infinity() || _ptime.is_pos_infinity())
      _nanoseconds = MAX_NANOSECONDS;
    if (_ptime.is_neg_infinity())
      _nanoseconds = MIN_NANOSECONDS;
    if (_ptime.is_not_a_date_time())
      _nanoseconds = MIN_NANOSECONDS;
  } else {
    _nanoseconds =
        nanosecondsFromDuration(_ptime - DateAndTimeHelpers::GPS_EPOCH);

    // Check for overflow
    if (_nanoseconds < 0) {
      if (_ptime.date().year() >= 1990) {
        // nanoseconds is negative despite the year being higher than 1990
        // ... means overflow occured
        this->setToMaximum();
      }
    } else if (_nanoseconds > 0) {
      if (_ptime.date().year() < 1990) {
        // Nanoseconds is positive but the year is below 1990 = it should be
        // negative!
        this->setToMinimum();
      }
    }
  }
}
Example #2
0
boost::posix_time::ptime
MetaModelConf::
findNextrun(const boost::posix_time::ptime &refTime)const
{
	ptime now( (nowTime__.is_special()?second_clock::universal_time():nowTime__) );
	ptime midnight( now.date(), time_duration(0, 0, 0, 0) );
	time_duration tdNow( now.time_of_day() );
	

	if( nextrun_.empty() )
		return ptime(); //Udefined.
	
	if( specType==Absolute) {
		TimeDurationList::const_iterator it=nextrun_.begin();
		for( ; it != nextrun_.end() && *it < tdNow ; ++it );

		if( it == nextrun_.end() ) {
			midnight += hours( 24 ); //next day
			it = nextrun_.begin();
		}

		return midnight + *it;
	} else if( specType == RelativeToLoadTime ){
		if( refTime.is_special() || nextrun_.empty())
			return ptime();  // undefined

		return refTime + (*nextrun_.begin());
	} else {
		return ptime();  // Undefined
	}
}
Example #3
0
 void update( const boost::posix_time::ptime& t, bool commit = false )
 {
     //std::cerr << "--> a: t_: " << ( t_ ? boost::posix_time::to_iso_string( *t_ ) : "none" ) << " t: " << boost::posix_time::to_iso_string( t ) << " commit: " << commit << std::endl;
     switch( how_ )
     {
         case first:
             if( !t_ ) { t_ = t; }
             break;
         case last:
             if( commit ) { t_ = t; }
             break;
         case max:
             if( !t_ ) { t_ = t; }
             if( t_->is_not_a_date_time() ) { break; }
             if( t.is_not_a_date_time() ) { t_ = boost::posix_time::not_a_date_time; } else if( *t_ < t ) { t_ = t; }
             break;
         case mean:
             if( t.is_special() || t.is_not_a_date_time() ) { break; }
             if( t_ && t_->is_not_a_date_time() ) { break; }
             if( t_ ) { ++count_; t_ = *t_ + ( t - *t_ ) / count_; }
             else { count_ = 1; t_ = t; }
             break;
         case middle:
             if( !t_ ) { t_ = t; }
             if( !commit ) { break; }
             if( t.is_special() || t.is_not_a_date_time() ) { t_ = boost::posix_time::not_a_date_time; }
             if( !t_->is_not_a_date_time() ) { t_ = *t_ + ( t - *t_ ) / 2; }
             break;
         case min:
             if( !t_ ) { t_ = t; }
             if( t_->is_not_a_date_time() ) { break; }
             if( t.is_not_a_date_time() ) { t_ = boost::posix_time::not_a_date_time; } else if( *t_ > t ) { t_ = t; }
             break;
     }
     //std::cerr << "--> b: t_: " << ( t_ ? boost::posix_time::to_iso_string( *t_ ) : "none" ) << std::endl << std::endl;
 }
Example #4
0
void 
webfw::
DefaultResponse::
expire( const boost::posix_time::ptime &exp )
{
   Response::expire( exp );
   
   if( ! exp.is_special() ) {                                 
      std::string rfc1123;                                       
      rfc1123 = miutil::rfc1123date( exp );                   
                                                                     
      if( ! rfc1123.empty() )
         out_ << "Expire: " << rfc1123 << std::endl;     
   }
}