std::vector<DateTimeEventsManager::EventStartTimePair> DateTimeEventsManager::GetEventsNearestStartTime() const { std::vector<EventStartTimePair> result; const std::vector<DateTimeEvent*> dateTimeEvents = GetDateTimeEvents(); for (auto it = dateTimeEvents.begin(); it != dateTimeEvents.end(); ++it) { DateTimeEvent* event = *it; const boost::posix_time::ptime eventStartTime = GetEventStartTime(event); // Skip once events in the past. if (eventStartTime.is_not_a_date_time()) { continue; } result.push_back(std::make_pair(event, eventStartTime)); } std::sort(result.begin(), result.end(), boost::bind(&EventStartTimePair::second, _1) < boost::bind(&EventStartTimePair::second, _2)); return result; }
inline boost::uint64_t hash_value(const boost::posix_time::ptime& value, boost::uint64_t seed) { seed = hash_value(value.date(), seed); seed = hash_value(value.time_of_day(), seed); return seed; }
int CH104_Transmit::AssembleSynTime(size_t bufIndex, unsigned char * buf, stSynTimePara para,boost::posix_time::ptime time) { size_t count = bufIndex; buf[count++] = 0x68; count += ValToBuf(&buf[count],0,FrameLenLength_); count += ValToBuf(&buf[count],para.IFrameSendCounter_,2); count += ValToBuf(&buf[count],para.IFrameRecvCounter_,2); count += ValToBuf(&buf[count],M_CS_NA_1,FrameTypeLength_); count += ValToBuf(&buf[count],0x01,InfoNumLength_); count += ValToBuf(&buf[count],trans_act,TransReasonLength_); count += ValToBuf(&buf[count],para.addr_,AsduAddrLength_); count += ValToBuf(&buf[count],0,InfoAddrLength_); boost::posix_time::time_duration td = time.time_of_day(); count += ValToBuf(&buf[count],td.total_milliseconds() % MinutesRemainderMillisecs,2); buf[count++] = td.minutes() & 0x3f; buf[count++] = td.hours() & 0x1f; boost::gregorian::date::ymd_type ymd = time.date().year_month_day(); //buf[count++] = ymd.day & 0x1f; buf[count++] = ((time.date().day_of_week()<<5) & 0xe0) | (ymd.day & 0x1f); buf[count++] = ymd.month & 0x0f; buf[count++] = ymd.year % 100; int len = count - bufIndex - (FrameLenLength_ + SYN_HEAD_LENGTH); ValToBuf(&buf[FrameLenLocation_],len,FrameLenLength_); return count - bufIndex; }
boost::posix_time::ptime ptime_truncate_milliseconds(const boost::posix_time::ptime &t) { if(t.is_not_a_date_time()) return t; boost::posix_time::time_duration time = t.time_of_day(); return boost::posix_time::ptime(t.date(), boost::posix_time::time_duration(time.hours(), time.minutes(), time.seconds())); }
QDateTime pttoqt(const boost::posix_time::ptime &pt) { boost::gregorian::date gd = pt.date(); boost::posix_time::time_duration gt = pt.time_of_day(); QDate qdate(gd.year(), gd.month(), gd.day()); QTime qtime(gt.hours(), gt.minutes(), gt.seconds()); return QDateTime(qdate, qtime); }
//! Convert a time to a tm structure truncating any fractional seconds inline std::tm to_tm(const boost::posix_time::ptime& t) { std::tm timetm = boost::gregorian::to_tm(t.date()); boost::posix_time::time_duration td = t.time_of_day(); timetm.tm_hour = td.hours(); timetm.tm_min = td.minutes(); timetm.tm_sec = td.seconds(); timetm.tm_isdst = -1; // -1 used when dst info is unknown return timetm; }
//! Convert a time to a tm structure truncating any fractional seconds inline tm to_tm(const boost::posix_time::ptime& t) { tm timetm = boost::gregorian::to_tm(t.date()); boost::posix_time::time_duration td = t.time_of_day(); timetm.tm_hour = td.hours(); timetm.tm_min = td.minutes(); timetm.tm_sec = td.seconds(); timetm.tm_isdst = -1; //? return timetm; }
string AutoFlight::af_timestamp() { const boost::posix_time::ptime time = boost::posix_time::second_clock::local_time(); stringstream timestamp; timestamp << setw(4) << setfill('0') << time.date().year() << setw(2) << time.date().month().as_number() << setw(2) << time.date().day().as_number(); timestamp << "T"; timestamp << setw(2) << time.time_of_day().hours() << setw(2) << time.time_of_day().minutes() << setw(2) << time.time_of_day().seconds(); return timestamp.str(); }
static void FromBoostPtime(const boost::posix_time::ptime& pt, Time& t) { boost::gregorian::date d = pt.date(); t.m_year = d.year(); t.m_month = d.month(); t.m_day = d.day(); boost::posix_time::time_duration tod = pt.time_of_day(); t.m_hour = tod.hours(); t.m_minute = tod.minutes(); t.m_second = tod.seconds(); t.m_fraction_of_second = tod.fractional_seconds() / pow(10.0, tod.num_fractional_digits()); }
void BindArgDataHolder::ArgSetter::operator()( MYSQL_BIND &arg, const boost::posix_time::ptime &datetime ) { MYSQL_TIME *ts = reinterpret_cast<MYSQL_TIME *>( arg.buffer ); ts->year = datetime.date().year(); ts->month = datetime.date().month(); ts->day = datetime.date().day(); ts->hour = datetime.time_of_day().hours(); ts->minute = datetime.time_of_day().minutes(); ts->second = datetime.time_of_day().seconds(); }
std::string TimeConversion::toString(const boost::posix_time::ptime ts, const int secPrecision) const { using namespace boost::posix_time; // determine the nanoseconds given in ts const int h = ts.time_of_day().hours(); const int m = ts.time_of_day().minutes(); const int s = ts.time_of_day().seconds(); const time_duration r = time_duration(h, m, s); const time_duration rest = ts.time_of_day() - r; const int nanoseconds = int(rest.total_nanoseconds()); // not more than 1 bil nanoseconds here. return toString(to_tm(ts), nanoseconds, secPrecision); }
void append_timestamp(Stream& stream, boost::posix_time::ptime timestamp) { auto date = timestamp.date(); auto time = timestamp.time_of_day(); auto milliseconds = time.fractional_seconds() / 1000; // microseconds to milliseconds std::wstringstream buffer; buffer << std::setfill(L'0') << L"[" << std::setw(4) << date.year() << L"-" << std::setw(2) << date.month().as_number() << "-" << std::setw(2) << date.day().as_number() << L" " << std::setw(2) << time.hours() << L":" << std::setw(2) << time.minutes() << L":" << std::setw(2) << time.seconds() << L"." << std::setw(3) << milliseconds << L"] "; stream << buffer.str(); }
uint16 ptime_milliseconds(const boost::posix_time::ptime &t) { boost::posix_time::time_duration duration = t.time_of_day(); uint64 milliseconds = duration.fractional_seconds() / 1000; OS_ASSERT(milliseconds < 1000); return static_cast<uint16>(milliseconds); }
void readTag( const std::string& tag, Session& session, const boost::posix_time::ptime& snapshotTime ){ IOVProxy proxy; if( snapshotTime.is_not_a_date_time() ) proxy = session.readIov( tag ); else proxy = session.readIov( tag, snapshotTime ); std::cout <<"> iov loaded size="<<proxy.loadedSize()<<std::endl; std::cout <<"> iov sequence size="<<proxy.sequenceSize()<<std::endl; IOVProxy::Iterator iovIt = proxy.find( 107 ); if( iovIt == proxy.end() ){ std::cout <<">[0] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[0] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<"#[0] payload="<<*pay0<<std::endl; } iovIt = proxy.find( 235 ); if( iovIt == proxy.end() ){ std::cout <<">[1] not found!"<<std::endl; } else { cond::Iov_t val = *iovIt; std::cout <<"#[1] iov since="<<val.since<<" till="<<val.till<<" pid="<<val.payloadId<<std::endl; boost::shared_ptr<std::string> pay0 = session.fetchPayload<std::string>( val.payloadId ); std::cout <<"#[1] payload="<<*pay0<<std::endl; } }
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 } }
void cluster_helper_c::create_tags_for_track_statistics(KaxTags &tags, std::string const &writing_app, boost::posix_time::ptime const &writing_date) { auto writing_date_str = !writing_date.is_not_a_date_time() ? mtx::date_time::to_string(writing_date, "%Y-%m-%d %H:%M:%S") : "1970-01-01 00:00:00"; for (auto const &ptzr : g_packetizers) { auto track_uid = ptzr.packetizer->get_uid(); auto const &stats = m->track_statistics[track_uid]; auto bps = stats.get_bits_per_second(); auto duration = stats.get_duration(); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "BPS"); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "DURATION"); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "NUMBER_OF_FRAMES"); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "NUMBER_OF_BYTES"); auto tag = mtx::tags::find_tag_for<KaxTagTrackUID>(tags, track_uid, mtx::tags::Movie, true); mtx::tags::set_target_type(*tag, mtx::tags::Movie, "MOVIE"); mtx::tags::set_simple(*tag, "BPS", to_string(bps ? *bps : 0)); mtx::tags::set_simple(*tag, "DURATION", format_timecode(duration ? *duration : 0)); mtx::tags::set_simple(*tag, "NUMBER_OF_FRAMES", to_string(stats.get_num_frames())); mtx::tags::set_simple(*tag, "NUMBER_OF_BYTES", to_string(stats.get_num_bytes())); mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_APP", writing_app); mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_DATE_UTC", writing_date_str); mtx::tags::set_simple(*tag, "_STATISTICS_TAGS", "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES"); } m->track_statistics.clear(); }
/** 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(); } } } }
static QString boostTimeToQString(const boost::posix_time::ptime &boostDate) { if (boostDate.is_not_a_date_time()) return ""; struct std::tm tm; try { tm = boost::posix_time::to_tm(boostDate); } catch(std::exception e) { return ""; } const time_t t = mktime(&tm); const QDateTime dt = QDateTime::fromTime_t(t); return dt.toString(Qt::DefaultLocaleLongDate); }
std::pair< comma::uint32, comma::uint32 > to_ntp_time( boost::posix_time::ptime t ) { if( t < ntp_base ) { COMMA_THROW_STREAM( comma::exception, "cannot convert to ntp time: " << t << ", which is less than NTP time base " << ntp_base ); } comma::int32 s = ( t - epoch_time ).total_seconds(); // 32 bit signed int in boost and posix comma::int32 m = t.time_of_day().total_microseconds() % 1000000; if( t >= epoch_time || m == 0 ) { return std::pair< comma::uint32, comma::uint32 >( static_cast< comma::uint32 >( ntp_diff + s ), static_cast< comma::uint32 >( m / ntp_microsec_coeff ) ); } else { return std::pair< comma::uint32, comma::uint32 >( static_cast< comma::uint32 >( ntp_diff + s - 1 ), static_cast< comma::uint32 >( m / ntp_microsec_coeff ) ); } }
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; } }
void PreparedStatement::bind(size_t param, const boost::posix_time::ptime &value) { if (value.is_not_a_date_time()) { bind(param, Null()); return; } ensure(param); m_paramValues[param - 1].resize(8); long long ticks = (value - postgres_epoch).total_microseconds(); *(long long *)&m_paramValues[param - 1][0] = byteswapOnLittleEndian(*(long long *)&ticks); m_params[param - 1] = m_paramValues[param - 1].c_str(); m_paramLengths[param - 1] = m_paramValues[param - 1].size(); m_paramFormats[param - 1] = 1; setType(param, TIMESTAMPOID); }
double getAlpha( boost::posix_time::ptime& tstamp_prev, double max_life) { auto now = boost::posix_time::microsec_clock::universal_time(); double alpha = 1.0; // Default is 100% opacity. if (!tstamp_prev.is_not_a_date_time()) { // alpha = min {delta_t, max_life} / max_life auto tdelta = now - tstamp_prev; alpha = tdelta.total_nanoseconds()/1000000000.; alpha = std::min(alpha, max_life); alpha /= max_life; } tstamp_prev = now; return alpha; }
void HistoryManager::appendEntryToFile(std::ofstream &os, bool isSent, const boost::posix_time::ptime &saveTime, const std::string &content) { if(saveTime.is_not_a_date_time()) return; if(os.tellp() != 0) os << std::endl; os << "[" << FormattingUtils::dateToStr(saveTime) << "]"; if(isSent) { os << "-S-"; } else { os << "-R-"; } os << content; }
boost::posix_time::ptime FileEndpoint::seek(boost::posix_time::ptime seek){ std::ifstream::pos_type position = 0; boost::posix_time::ptime timestamp; try{ in_file_stream.clear(); if(!seek.is_not_a_date_time()){ std::string line; while(std::getline(in_file_stream, line)){ std::istringstream iss(line); boost::posix_time::time_input_facet *timefacet = new boost::posix_time::time_input_facet(timestamp_format.c_str()); iss.imbue(std::locale(iss.getloc(), timefacet)); iss >> timestamp; if(timestamp>seek){ break; } position = in_file_stream.tellg(); } } in_file_stream.clear(); in_file_stream.seekg(position); }catch (std::ifstream::failure e){
void rotate_stores() { std::cout << "Rotating store " << store_file << "..." << std::endl; std::cout << "Rotating store call flush " << store_file << "..." << std::endl; fflush(stdout); try { store->flush(true); } catch (klio::StoreException const& ex) { std::cout << "Failed to flush the buffers : " << ex.what() << std::endl; } std::cout << "Rotating store flushed " << store_file << "..." << std::endl; fflush(stdout); std::cout << "Reopening store" << std::endl; const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); std::string s; s= str( format("%04d%02d%02d-%02d%02d") % now.date().year_month_day().year % now.date().year_month_day().month.as_number() % now.date().year_month_day().day.as_number() % now.time_of_day().hours() % now.time_of_day().minutes()); std::string name(store_file.string()); name+="."; name+=s; bfs::path dbname(name); std::cout << "===> renaming to: "<< name<<std::endl; fflush(stdout); try { store->rotate(dbname); } catch (klio::StoreException const& ex) { std::cout << "Failed to rotate the klio-databse : " << ex.what() << std::endl; } #if KLIO_AUTOCOMMIT store->start_transaction(); #endif std::cout << "Rotation done" << std::endl; }
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; }
NonOptionalValuePrettyPrint::result_type NonOptionalValuePrettyPrint::operator()(const boost::posix_time::ptime &value) const { return boost::gregorian::to_iso_extended_string(value.date()) + std::string(" ") + boost::posix_time::to_simple_string(value.time_of_day()); }
int Year() { return t.date().year(); };
bool ptime_is_valid(const boost::posix_time::ptime &t) { return (t.is_not_a_date_time() == false); }
void CBF533_CfgFile::Creat_HistoricalData(int linenum,boost::posix_time::ptime time) { std::stringstream ss1,ss2; FileSystem::CMarkup xml; std::string str1; std::string str2; // char Time[50]; // char Name[20]; int year,month,day,hour,min; boost::posix_time::time_duration td = time.time_of_day(); boost::gregorian::date::ymd_type ymd = time.date().year_month_day(); int Sec = ((td.total_milliseconds() % (1000*60*60))% (1000*60)) / (1000); int Msec = ((td.total_milliseconds() % (1000*60*60))% (1000*60)) % (1000); year = ymd.year; month = ymd.month; day = ymd.day; hour = td.hours(); min = td.minutes(); ss1 <<"/mnt/"<<year<<month<<day<<".xml"; ss1 >> str1; std::cout<<"文件名为:"<< str1 <<std::endl; ss2 <<year<<"/"<<month<<"/"<<day<<"-"<<hour<<":"<<min<<":"<<Sec<<":"<<Msec; ss2 >> str2; // std::cout<<"现在时间是:"<< str2 <<std::endl; xml.SetDoc("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n"); xml.AddElem( "HistoricalData" ); xml.SetAttrib( "LineSum",linenum); xml.AddChildElem( "ExtremumRecordNode" ); xml.IntoElem(); for(int i = 0;i < linenum;i ++) { xml.AddChildElem( "ExtremumVal" ); xml.SetChildAttrib( "LineNo",i); xml.IntoElem(); xml.AddChildElem( "MaxUa","0"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MinUa","5770"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MaxUb","0"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MinUb","5770"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MaxUc","0"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MinUc","5770"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MaxIa","0"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MinIa","5000"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MaxIb","0"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MinIb","5000"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MaxIc","0"); xml.SetChildAttrib( "Time",str2); xml.AddChildElem( "MinIc","5000"); xml.SetChildAttrib( "Time",str2); xml.OutOfElem(); } xml.OutOfElem(); xml.Save(str1); }