예제 #1
0
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;
}
예제 #2
0
파일: ip.cpp 프로젝트: zwj/statana
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);
}
예제 #3
0
 /*!\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;
   }
 }
예제 #4
0
// 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;
}
예제 #5
0
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;
}
예제 #6
0
 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();
 }
예제 #7
0
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;
}
 /*! 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());
 }
 /*! Adds a months object to a ptime. Result will be same 
  * day-of-month as ptime unless original day was the last day of month.
  * see date_time::months_duration for more details */
 inline
 ptime 
 operator+=(ptime& t, const boost::gregorian::months& m)
 {
   // get_neg_offset returns a negative duration, so we add
   return t += m.get_offset(t.date());
 }
예제 #10
0
 //              //
 // constructors //
 //              //  
 explicit scale_with_holidays(const ptime& start, long frequency=1, time_zone_const_ptr tz=nullptr, holidays_const_ptr hol=nullptr) : _frequency(frequency), _holidays(hol), _position(0) { 
   if(start.is_special())
     throw std::logic_error("the start time cannot be a special value");
   if(_frequency <= 0)
     throw std::logic_error("frequency must be positive");
   _base.reset(detail::helper<BaseScale>::create(start, tz));
   back_to_non_holiday();
 }
예제 #11
0
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;
}
예제 #12
0
    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);

    }
예제 #13
0
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;
  }  
}
 /*! Subtracts a months object from a ptime. Result will be same 
  * day-of-month as ptime unless original day was the last day of month.
  * see date_time::months_duration for more details */
 inline
 ptime 
 operator-=(ptime& t, const boost::gregorian::months& m)
 {
   return t += m.get_neg_offset(t.date());
 }
 /*! Adds a months object and a ptime. Result will be same 
  * day-of-month as ptime unless original day was the last day of month.
  * see date_time::months_duration for more details */
 inline
 ptime 
 operator+(const ptime& t, const boost::gregorian::months& m)
 {
   return t + m.get_offset(t.date());
 }
예제 #16
0
 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())));
 }
예제 #17
0
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(),
		    tr("October").str(), tr("November").str(), tr("December").str()};
		dateFacet->long_month_names(months);

		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_SHORT_FORMAT);
	ss << getPtime(this->ticks).date();
	return ss.str();
}

UString GameTime::getWeekString() const { return format("%s %d", tr("Week"), 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;
}

unsigned int GameTime::getDay() const { return getPtime(this->ticks).date().day(); }

unsigned int GameTime::getHours() const { return getPtime(this->ticks).time_of_day().hours(); }

unsigned int GameTime::getMinutes() const { return getPtime(this->ticks).time_of_day().minutes(); }

uint64_t GameTime::getTicks() const { return ticks; }

bool GameTime::secondPassed() const { return secondPassedFlag; }

bool GameTime::fiveMinutesPassed() const { return fiveMinutesPassedFlag; }

bool GameTime::hourPassed() const { return hourPassedFlag; }

bool GameTime::dayPassed() const { return dayPassedFlag; }

bool GameTime::weekPassed() const { return weekPassedFlag; }

void GameTime::clearFlags()
{
	secondPassedFlag = false;
	fiveMinutesPassedFlag = false;
	hourPassedFlag = false;
	dayPassedFlag = false;
	weekPassedFlag = false;
}

void GameTime::addTicks(uint64_t ticks)
{
	this->ticks += ticks;
	uint64_t secondTicks = this->ticks % (TICKS_PER_SECOND);
	uint64_t fiveMinutesTicks = this->ticks % (5 * TICKS_PER_MINUTE);
	if (fiveMinutesTicks < ticks)
	{
		secondPassedFlag = true;
		fiveMinutesPassedFlag = true;
		uint64_t hourTicks = this->ticks % TICKS_PER_HOUR;
		if (hourTicks < ticks)
		{
			hourPassedFlag = true;
			uint64_t dayTicks = this->ticks % TICKS_PER_DAY;
			if (dayTicks < ticks)
			{
				uint64_t days = this->ticks / TICKS_PER_DAY;
				dayPassedFlag = true;
				if (days % 7 == 0)
				{
					weekPassedFlag = true;
				}
			}
		}
	}
	else
	{
		if (secondTicks < ticks)
		{
			secondPassedFlag = true;
		}
	}
}

GameTime GameTime::midday() { return GameTime(TICKS_PER_HOUR * 12); }
} // namespace OpenApoc
예제 #18
0
 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(start - boost::posix_time::time_duration(0,0,0,td.fractional_seconds() % 1000));
 }
예제 #19
0
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;
}
예제 #20
0
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();
}
예제 #21
0
파일: Edge.cpp 프로젝트: Tisseo/synthese
		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();
		}
예제 #22
0
파일: Edge.cpp 프로젝트: Tisseo/synthese
		ServicePointer Edge::getNextService(const AccessParameters& accessParameters,
			ptime departureMoment,
			const ptime& maxDepartureMoment,
			bool checkIfTheServiceIsReachable,
			optional<DepartureServiceIndex::Value>& minNextServiceIndex,
			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() || (!enableTheoretical && !enableRealTime))
			{
				return ServicePointer();
			}

			bool RTData(enableRealTime && departureMoment < posix_time::second_clock().local_time() + posix_time::hours(23));

			// Search schedule
			DepartureServiceIndex::Value next(getDepartureFromIndex(RTData, departureMoment.time_of_day().hours()));

			if(	minNextServiceIndex &&
				(*minNextServiceIndex == services.end() || services.value_comp()(*next, **minNextServiceIndex))
			){
				next = *minNextServiceIndex;
			}

			while ( departureMoment <= maxDepartureMoment )  // boucle sur les dates
			{
				// Look in schedule for when the line is in service
				if(	getParentPath()->isActive(departureMoment.date()))
				{
					for (; next != services.end(); ++next)  // boucle sur les services
					{
						// Saving of the used service
						ServicePointer servicePointer(
							(*next)->getFromPresenceTime(
								accessParameters,
								enableTheoretical,
								RTData,
								true,
								*this,
								departureMoment,
								checkIfTheServiceIsReachable,
								inverted,
								ignoreReservation,
								allowCanceled
							)
						);

						if (!servicePointer.getService())
							continue;

						// Check of validity of departure date time
						if (servicePointer.getDepartureDateTime() > maxDepartureMoment )
						{
							return ServicePointer();
						}

						// Limitation of the continuous service range at the specified bounds
						if(servicePointer.getDepartureDateTime() + servicePointer.getServiceRange() > maxDepartureMoment)
						{
							servicePointer.setServiceRange(maxDepartureMoment - servicePointer.getDepartureDateTime());
						}

						// Store the service rank in edge
						minNextServiceIndex = next;

						// The service is now returned
						return servicePointer;
				}	}

				if (departureMoment.time_of_day().hours() < 3)
					departureMoment = ptime(departureMoment.date(), hours(3));
				else
					departureMoment = ptime(departureMoment.date(), hours(27));

				next = _departureIndex[0].get(RTData);
			}

			return ServicePointer();
		}
예제 #23
0
		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()));
		}
 /*! Adds a years object to 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+=(ptime& t, const boost::gregorian::years& y)
 {
   return t += y.get_offset(t.date());
 }
예제 #25
0
파일: datetime.cpp 프로젝트: azyr/sjlib
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);
}
예제 #26
0
 static std::string str (const ptime& start, const ptime& end) {
   return boost::posix_time::to_iso_string(ptime(start.date(), boost::posix_time::time_duration(start.time_of_day().hours(), 0, 0)));
 }