本文整理汇总了C++中ptime类的典型用法代码示例。如果您正苦于以下问题:C++ ptime类的具体用法?C++ ptime怎么用?C++ ptime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ptime类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: _boostTimezoneLocalPTimeToUTCTimestamps
UTCTimestampsForLocalTime _boostTimezoneLocalPTimeToUTCTimestamps(
ptime local_pt,
time_zone_ptr tz
) {
UTCTimestampsForLocalTime res;
auto local_date = local_pt.date();
auto local_time = local_pt.time_of_day();
auto save_timestamp_if_valid = [&](bool is_dst, time_t *out) {
try {
auto local_dt = local_date_time(local_date, local_time, tz, is_dst);
// local_date_time() ignores is_dst if the timezone does not have
// DST (instead of throwing dst_not_valid). So, we must confirm
// that our is_dst guess was correct to avoid storing the same
// timestamp in both fields of res (same as problem (b) in the
// localtime_r code path).
if (local_dt.is_dst() == is_dst) {
*out = (local_dt.utc_time() - from_time_t(0)).total_seconds();
}
} catch (dst_not_valid& e) {
// Continue, we're trying both values of is_dst
}
};
try {
save_timestamp_if_valid(true, &res.dst_time);
save_timestamp_if_valid(false, &res.non_dst_time);
} catch (time_label_invalid& e) {
// This local time label was skipped by DST, so res will be empty.
}
return res;
}
开发者ID:conkeyn,项目名称:bistro,代码行数:32,代码来源:date_time.cpp
示例2: time_duration
time::time(ptime now_time)
{
gregorian::date now_d = now_time.date();
time_duration now_td = now_time.time_of_day();
time_duration td = time_duration(now_td.hours(), 0, 0);
_imp = ptime(now_d, td);
}
开发者ID:zwj,项目名称:statana,代码行数:7,代码来源:ip.cpp
示例3: to_iso_string
/*!\ingroup time_format
*/
inline
std::string to_iso_string(ptime t)
{
std::string ts = gregorian::to_iso_string(t.date());// + "T";
if(!t.time_of_day().is_special()) {
return ts + "T" + to_iso_string(t.time_of_day());
}
else {
return ts;
}
}
开发者ID:AlexMioMio,项目名称:boost,代码行数:13,代码来源:time_formatters_limited.hpp
示例4: ComposeOptionName
// something similar in BuildSymbolName.cpp
void ComposeOptionName(
std::string& sCall, std::string& sPut,
const std::string& sUnderlying, ou::tf::OptionSide::enumOptionSide option, ptime dtExpiry, double dblStrike ) {
std::string sDay;
boost::gregorian::date::day_type day = dtExpiry.date().day();
sDay = ( ( 9 < day ) ? "" : "0" ) + boost::lexical_cast<std::string>( day );
std::string sYear = boost::lexical_cast<std::string>( dtExpiry.date().year() );
std::string sStrike = boost::lexical_cast<std::string>( dblStrike );
sCall = sUnderlying + sYear.substr( 2, 2 ) + sDay + rchCallMonth[ dtExpiry.date().month() - 1 ] + sStrike;
sPut = sUnderlying + sYear.substr( 2, 2 ) + sDay + rchPutMonth[ dtExpiry.date().month() - 1 ] + sStrike;
}
开发者ID:rburkholder,项目名称:trade-frame,代码行数:12,代码来源:Option.cpp
示例5: f
int FlowRead::f(ptime time, int dt) {
boost::gregorian::date gd = time.date();
boost::posix_time::time_duration gt = time.time_of_day();
QDate qdate(gd.year(), gd.month(), gd.day());
QTime qtime(gt.hours(), gt.minutes(), gt.seconds());
QDateTime current(qdate, qtime);
ctxt.setOutPort(&out, current, dt);
return dt;
}
开发者ID:christianurich,项目名称:CityDrain3,代码行数:12,代码来源:flowread.cpp
示例6: scale_with_holidays
scale_with_holidays(const ptime& tm, const ptime& start, long frequency=1, time_zone_const_ptr tz=nullptr, holidays_const_ptr hol=nullptr) : _frequency(frequency), _holidays(hol) {
if(tm.is_special())
throw std::logic_error("the time to point to cannot be a special value");
if(_frequency <= 0)
throw std::logic_error("frequency must be positive");
if(start.is_special())
_base.reset(detail::helper<BaseScale>::create(tm, tm, tz));
else
_base.reset(detail::helper<BaseScale>::create(tm, start, tz));
back_to_non_holiday();
update_position();
}
开发者ID:tr11,项目名称:timescales,代码行数:12,代码来源:scale_with_holidays.hpp
示例7:
/*! Subtracts a years object and a ptime. Result will be same
* month and day-of-month as ptime unless original day was the
* last day of month. see date_time::years_duration for more details */
inline
ptime
operator-(const ptime& t, const boost::gregorian::years& y)
{
// get_neg_offset returns a negative duration, so we add
return t + y.get_neg_offset(t.date());
}
开发者ID:toddmallen,项目名称:the_coldest_sea,代码行数:10,代码来源:date_duration_operators.hpp
示例8: MakeDateTime
RtcDateTime MakeDateTime(ptime time, Meridiem period)
{
auto d = time.time_of_day();
auto hour = d.hours();
auto minute = d.minutes();
auto second = d.seconds();
auto mode = period == Meridiem::None
? ClockMode::MilitaryClock
: ClockMode::WallClock;
if (period != Meridiem::None)
{
if (hour == 0 && minute <= 59)
{
hour += 12;
}
else if (hour >= 13 && hour <= 23)
{
hour -= 12;
}
}
auto doy = byte(time.date().day_of_week());
auto mon = byte(time.date().month());
auto weekDay = pvt::ToDayOfWeek(doy);
auto month = pvt::ToMonth(mon);
auto day = int(time.date().day());
auto year = int(time.date().year());
printf("y: %d, m: %d, dy: %d, dt: %d, hh: %d, mm: %d, ss: %d\n",
year, mon, doy, day, hour, minute, second);
RtcDateTime result(RtcTime(period, hour, minute, second, mode),
day,
weekDay,
month,
year);
printf("rtc datetime: %s\n", result.AsString().c_str());
return result;
}
开发者ID:jakesays,项目名称:raspberrypi,代码行数:43,代码来源:rtctest.cpp
示例9: throw
DSTRule::DSTRule (TZInfoIter info1, TZInfoIter info2,
ptime date1, ptime date2) :
to_std(date1.date()), to_dst(date2.date()),
to_std_time(date1.time_of_day()), to_dst_time(date2.time_of_day()),
std_info(info1), dst_info(info2)
{
if (info1->info.isdst == info2->info.isdst)
throw(std::invalid_argument("Both infos have the same dst value."));
if (info1->info.isdst && !info2->info.isdst)
{
std::swap(to_std, to_dst);
std::swap(to_std_time, to_dst_time);
std::swap(std_info, dst_info);
}
if (dst_info->isgmt)
to_dst_time += boost::posix_time::seconds(dst_info->info.gmtoff);
if (std_info->isgmt)
to_std_time += boost::posix_time::seconds(std_info->info.gmtoff);
}
开发者ID:Isendir,项目名称:gnucash,代码行数:20,代码来源:gnc-timezone.cpp
示例10: date
Time::Time(ptime t)
{
auto datePart = t.date();
auto timePart = t.time_of_day();
TimeScale timeScale = TimeScale::Master();
// consider date part only
auto d = datePart - date(1970, 1, 1);
int offsetFromEpochDays = d.days();
this->ticks_ = timeScale.TicksPerDay() * offsetFromEpochDays;
// add ticks for time of day
if(time_duration::ticks_per_second() > timeScale.TicksPerSecond()) // since the following computations are integer calculcations, we distinguish here
{
int64 conversionRate = time_duration::ticks_per_second() / timeScale.TicksPerSecond();
this->ticks_ += timePart.ticks() / conversionRate;
}
else
{
int64 conversionRate = timeScale.TicksPerSecond() / time_duration::ticks_per_second();
this->ticks_ += timePart.ticks() * conversionRate;
}
}
开发者ID:jackchang,项目名称:TeaFiles.Cpp,代码行数:24,代码来源:Time.cpp
示例11: str
static std::string str (const ptime& start, const ptime& end) {
boost::posix_time::time_duration td(start.time_of_day());
return boost::posix_time::to_iso_string(ptime(start.date(), boost::posix_time::time_duration(td.hours(), td.minutes(), td.seconds())));
}
开发者ID:tr11,项目名称:timescales,代码行数:4,代码来源:scale_labeler.hpp
示例12: ptime
namespace OpenApoc
{
static const ptime GAME_START = ptime(date(2084, Mar, 7), time_duration(0, 0, 0));
static std::locale *TIME_LONG_FORMAT = nullptr;
static std::locale *TIME_SHORT_FORMAT = nullptr;
static std::locale *DATE_LONG_FORMAT = nullptr;
static std::locale *DATE_SHORT_FORMAT = nullptr;
// FIXME: Refactor to always use ptime instead of ticks?
static time_duration ticksToPosix(int64_t ticks)
{
int64_t tickTotal = std::round(static_cast<double>(ticks * time_duration::ticks_per_second()) /
TICKS_PER_SECOND);
return time_duration(0, 0, 0, tickTotal);
}
GameTime::GameTime(uint64_t ticks) : ticks(ticks){};
static boost::posix_time::ptime getPtime(uint64_t ticks)
{
return GAME_START + ticksToPosix(ticks);
}
UString GameTime::getLongTimeString() const
{
std::stringstream ss;
if (TIME_LONG_FORMAT == nullptr)
{
// locale controls the facet
time_facet *timeFacet = new time_facet("%H:%M:%S");
TIME_LONG_FORMAT = new std::locale(std::locale::classic(), timeFacet);
}
ss.imbue(*TIME_LONG_FORMAT);
ss << getPtime(this->ticks);
return ss.str();
}
UString GameTime::getShortTimeString() const
{
std::stringstream ss;
if (TIME_SHORT_FORMAT == nullptr)
{
// locale controls the facet
time_facet *timeFacet = new time_facet("%H:%M");
TIME_SHORT_FORMAT = new std::locale(std::locale::classic(), timeFacet);
}
ss.imbue(*TIME_SHORT_FORMAT);
ss << getPtime(this->ticks);
return ss.str();
}
UString GameTime::getLongDateString() const
{
std::stringstream ss;
if (DATE_LONG_FORMAT == nullptr)
{
apoc_date_facet *dateFacet = new apoc_date_facet("%A, %E %B, %Y");
DATE_LONG_FORMAT = new std::locale(std::locale::classic(), dateFacet);
std::vector<std::string> months = {
tr("January").str(), tr("February").str(), tr("March").str(),
tr("April").str(), tr("May").str(), tr("June").str(),
tr("July").str(), tr("August").str(), tr("September").str(),
tr("October").str(), tr("November").str(), tr("December").str()};
dateFacet->long_month_names(months);
std::vector<std::string> weekdays = {
tr("Sunday").str(), tr("Monday").str(), tr("Tuesday").str(), tr("Wednesday").str(),
tr("Thursday").str(), tr("Friday").str(), tr("Saturday").str()};
dateFacet->long_weekday_names(weekdays);
std::vector<std::string> days = {
tr("1st").str(), tr("2nd").str(), tr("3rd").str(), tr("4th").str(),
tr("5th").str(), tr("6th").str(), tr("7th").str(), tr("8th").str(),
tr("9th").str(), tr("10th").str(), tr("11th").str(), tr("12th").str(),
tr("13th").str(), tr("14th").str(), tr("15th").str(), tr("16th").str(),
tr("17th").str(), tr("18th").str(), tr("19th").str(), tr("20th").str(),
tr("21st").str(), tr("22nd").str(), tr("23rd").str(), tr("24th").str(),
tr("25th").str(), tr("26th").str(), tr("27th").str(), tr("28th").str(),
tr("29th").str(), tr("30th").str(), tr("31st").str()};
dateFacet->longDayNames(days);
}
ss.imbue(*DATE_LONG_FORMAT);
ss << getPtime(this->ticks).date();
return ss.str();
}
UString GameTime::getShortDateString() const
{
std::stringstream ss;
if (DATE_SHORT_FORMAT == nullptr)
{
apoc_date_facet *dateFacet = new apoc_date_facet("%E %B, %Y");
DATE_SHORT_FORMAT = new std::locale(std::locale::classic(), dateFacet);
std::vector<std::string> months = {
tr("January").str(), tr("February").str(), tr("March").str(),
tr("April").str(), tr("May").str(), tr("June").str(),
tr("July").str(), tr("August").str(), tr("September").str(),
//.........这里部分代码省略.........
开发者ID:JonnyH,项目名称:OpenApoc,代码行数:101,代码来源:gametime.cpp
示例13: getDateOffsetSeconds
int64_t getDateOffsetSeconds(const int64_t time) {
const ptime t(date(1970, 1, 1), seconds(time));
boost::gregorian::date_duration dd = t.date() - date(1970, 1, 1);
return dd.days() * 24 * 60 * 60;
}
开发者ID:eamsen,项目名称:transit-planner,代码行数:5,代码来源:Utilities.cpp
示例14: getWeekday
string getWeekday(const int64_t time) {
const ptime t(date(1970, 1, 1), seconds(time));
boost::gregorian::date d = t.date();
boost::gregorian::greg_weekday wd = d.day_of_week();
return wd.as_long_string();
}
开发者ID:eamsen,项目名称:transit-planner,代码行数:6,代码来源:Utilities.cpp
示例15: sharedServicesLock
ServicePointer Edge::getPreviousService(const AccessParameters& accessParameters,
ptime arrivalMoment,
const ptime& minArrivalMoment,
bool checkIfTheServiceIsReachable,
optional<ArrivalServiceIndex::Value>& maxPreviousServiceIndex,
bool inverted,
bool ignoreReservation,
bool allowCanceled,
bool enableTheoretical,
bool enableRealTime
) const {
boost::shared_lock<util::shared_recursive_mutex> sharedServicesLock(
*getParentPath()->sharedServicesMutex
);
const ServiceSet& services(getParentPath()->getServices());
if(services.empty())
{
return ServicePointer();
}
bool RTData(enableRealTime && arrivalMoment < posix_time::second_clock().local_time() + posix_time::hours(23));
ArrivalServiceIndex::Value previous(getArrivalFromIndex(RTData, arrivalMoment.time_of_day().hours()));
if( maxPreviousServiceIndex &&
(*maxPreviousServiceIndex == services.rend() || services.value_comp()(**maxPreviousServiceIndex, *previous))
){
previous = *maxPreviousServiceIndex;
}
while ( arrivalMoment >= minArrivalMoment ) // Loop over dates
{
if( getParentPath()->isActive(arrivalMoment.date()))
{
for (; previous != services.rend(); ++previous) // Loop over services
{
// Saving of the used service
ServicePointer servicePointer(
(*previous)->getFromPresenceTime(
accessParameters,
enableTheoretical,
RTData,
false,
*this,
arrivalMoment,
checkIfTheServiceIsReachable,
inverted,
ignoreReservation,
allowCanceled
)
);
if (!servicePointer.getService())
continue;
// Check of validity of departure date time
if (servicePointer.getArrivalDateTime() + servicePointer.getServiceRange() < minArrivalMoment)
{
return ServicePointer();
}
// Limitation of the continuous service range at the specified bounds
if(servicePointer.getArrivalDateTime() < minArrivalMoment)
{
time_duration toShift(minArrivalMoment - servicePointer.getArrivalDateTime());
servicePointer.shift(toShift);
servicePointer.setServiceRange(servicePointer.getServiceRange() - toShift);
}
// Store service rank in edge
maxPreviousServiceIndex = previous;
// The service is now returned
return servicePointer;
} }
arrivalMoment = ptime(arrivalMoment.date(), -seconds(1));
previous = _arrivalIndex[INDICES_NUMBER - 1].get(RTData);
}
return ServicePointer();
}
开发者ID:Tisseo,项目名称:synthese,代码行数:83,代码来源:Edge.cpp
示例16: insert
void ParametersMap::insert(
const std::string& parameterName,
const ptime& value
){
insert(parameterName, value.is_not_a_date_time() ? string() : to_iso_extended_string(value.date()) + " " + to_simple_string(value.time_of_day()));
}
开发者ID:Tisseo,项目名称:synthese,代码行数:6,代码来源:ParametersMap.cpp
示例17: ditr
time_period sj::weekday_period::get_relevant_period(const ptime& time) const
{
ptime start_time;
day_iterator ditr(time.date() + days(1), 1);
for (int i = 0; i < 14; i++)
{
if (ditr->day_of_week() == _sday)
{
local_date_time ldt(not_a_date_time);
if (_stime.dst())
{
ldt = local_date_time(*ditr, _stime.time(), _stime.timezone(),
_stime.dst().get());
}
else
{
static local_date_time::DST_CALC_OPTIONS ERR =
local_date_time::EXCEPTION_ON_ERROR;
ldt = local_date_time(*ditr, _stime.time(), _stime.timezone(),
ERR);
}
ptime start_time_candidate = ldt.utc_time();
if (start_time_candidate < time)
{
start_time = start_time_candidate;
break;
}
}
--ditr;
}
if (start_time.is_not_a_date_time())
{
throw std::logic_error("weekday_period::contains(): start_time "
"could not be determined");
}
ptime end_time;
ditr = day_iterator(start_time.date() - days(1), 1);
for (int i = 0; i < 9; i++)
{
if (ditr->day_of_week() == _eday)
{
local_date_time ldt(not_a_date_time);
if (_etime.dst())
{
ldt = local_date_time(*ditr, _etime.time(), _etime.timezone(),
_etime.dst().get());
}
else
{
static local_date_time::DST_CALC_OPTIONS ERR =
local_date_time::EXCEPTION_ON_ERROR;
ldt = local_date_time(*ditr, _etime.time(), _etime.timezone(),
ERR);
}
ptime end_time_candidate = ldt.utc_time();
if (end_time_candidate > start_time)
{
end_time = end_time_candidate;
break;
}
}
++ditr;
}
if (end_time.is_not_a_date_time())
{
throw std::logic_error("weekday_period::contains(): end_time "
"could not be determined");
}
return time_period(start_time, end_time);
}
开发者ID:azyr,项目名称:sjlib,代码行数:72,代码来源:datetime.cpp
示例18: getWeek
unsigned int GameTime::getWeek() const
{
date firstMonday = previous_weekday(GAME_START.date(), greg_weekday(Monday));
date lastMonday = previous_weekday(getPtime(this->ticks).date(), greg_weekday(Monday));
date_duration duration = lastMonday - firstMonday;
return duration.days() / 7 + 1;
}
开发者ID:JonnyH,项目名称:OpenApoc,代码行数:7,代码来源:gametime.cpp
注:本文中的ptime类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论