예제 #1
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;
   }
 }
예제 #2
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;
}
예제 #3
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);
}
예제 #4
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);

    }
예제 #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
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;
}
예제 #7
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;
  }  
}
예제 #8
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())));
 }
예제 #9
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)));
 }
예제 #10
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));
 }
예제 #11
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();
		}
예제 #12
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();
		}
예제 #13
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()));
		}