本文整理汇总了C++中boost::posix_time::ptime类的典型用法代码示例。如果您正苦于以下问题:C++ ptime类的具体用法?C++ ptime怎么用?C++ ptime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ptime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDateTimeEvents
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;
}
示例2: hash_value
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;
}
示例3: ValToBuf
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;
}
示例4: pttoqt
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);
}
示例5: to_tm
//! 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;
}
示例6: to_tm
//! 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;
}
示例7: af_timestamp
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();
}
示例8: FromBoostPtime
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());
}
示例9:
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();
}
示例10: toString
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);
}
示例11: append_timestamp
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();
}
示例12: readTag
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;
}
}
示例13: findNextrun
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
}
}
示例14:
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();
}
示例15: set_from_ptime
/** 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();
}
}
}
}