Example #1
0
    static time_type create_time(TZ_FOR_CREATE tz) {
      timeval tv;
      gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
      std::time_t t = tv.tv_sec;
      boost::uint32_t fs = tv.tv_usec;
      std::tm curr, *curr_ptr = 0;
      if (tz == LOCAL) {
        curr_ptr = c_time::localtime(&t, &curr);
      } else {
        curr_ptr = c_time::gmtime(&t, &curr);
      }
      date_type d(curr_ptr->tm_year + 1900,
                  curr_ptr->tm_mon + 1,
                  curr_ptr->tm_mday);
      //The following line will adjusts the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = resolution_traits_type::res_adjust()/1000000;

      time_duration_type td(curr_ptr->tm_hour,
                            curr_ptr->tm_min,
                            curr_ptr->tm_sec,
                            fs*adjust);
      return time_type(d,td);

    }
	high_resolution_timer::high_resolution_timer(io_service& io_service,
		const duration_type& expiry_time)
		: m_expiration_time(time_type())
		, m_io_service(io_service)
		, m_expired(true)
	{
		expires_from_now(expiry_time);
	}
Example #3
0
 static time_type create_time(::std::tm* current)
 {
   date_type d(static_cast<unsigned short>(current->tm_year + 1900),
               static_cast<unsigned short>(current->tm_mon + 1),
               static_cast<unsigned short>(current->tm_mday));
   time_duration_type td(current->tm_hour,
                         current->tm_min,
                         current->tm_sec);
   return time_type(d,td);
 }
Example #4
0
 static time_type local_time(shared_ptr<time_zone_type> tz_ptr) {
   typedef typename time_type::utc_time_type utc_time_type;
   typedef second_clock<utc_time_type> second_clock;
   // we'll need to know the utc_offset this machine has
   // in order to get a utc_time_type set to utc
   utc_time_type utc_time = second_clock::universal_time();
   time_duration_type utc_offset = second_clock::local_time() - utc_time;
   // use micro clock to get a local time with sub seconds
   // and adjust it to get a true utc time reading with sub seconds
   utc_time = microsec_clock<utc_time_type>::local_time() - utc_offset;
   return time_type(utc_time, tz_ptr);
 }
    static time_type create_time(time_converter converter)
    {
#ifdef BOOST_HAS_GETTIMEOFDAY
      timeval tv;
      gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
      std::time_t t = tv.tv_sec;
      boost::uint32_t sub_sec = tv.tv_usec;
#elif defined(BOOST_HAS_FTIME)
      boost::winapi::FILETIME_ ft;
      boost::winapi::GetSystemTimeAsFileTime(&ft);
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
      // Some runtime library implementations expect local times as the norm for ctime functions.
      {
        boost::winapi::FILETIME_ local_ft;
        boost::winapi::FileTimeToLocalFileTime(&ft, &local_ft);
        ft = local_ft;
      }
#endif

      boost::uint64_t micros = file_time_to_microseconds(ft); // it will not wrap, since ft is the current time
                                                              // and cannot be before 1970-Jan-01
      std::time_t t = static_cast<std::time_t>(micros / 1000000UL); // seconds since epoch
      // microseconds -- static casts suppress warnings
      boost::uint32_t sub_sec = static_cast<boost::uint32_t>(micros % 1000000UL);
#else
#error Internal Boost.DateTime error: BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK is defined, however neither gettimeofday nor FILETIME support is detected.
#endif

      std::tm curr;
      std::tm* curr_ptr = converter(&t, &curr);
      date_type d(static_cast< typename date_type::year_type::value_type >(curr_ptr->tm_year + 1900),
                  static_cast< typename date_type::month_type::value_type >(curr_ptr->tm_mon + 1),
                  static_cast< typename date_type::day_type::value_type >(curr_ptr->tm_mday));

      //The following line will adjust the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = static_cast< int >(resolution_traits_type::res_adjust() / 1000000);

      time_duration_type td(static_cast< typename time_duration_type::hour_type >(curr_ptr->tm_hour),
                            static_cast< typename time_duration_type::min_type >(curr_ptr->tm_min),
                            static_cast< typename time_duration_type::sec_type >(curr_ptr->tm_sec),
                            sub_sec * adjust);

      return time_type(d,td);
    }
  inline
  time_type
  parse_iso_time(const std::string& s, char sep)
  {
    typedef typename time_type::time_duration_type time_duration;
    typedef typename time_type::date_type date_type;

    //split date/time on a unique delimiter char such as ' ' or 'T'
    std::string date_string, tod_string;
    split(s, sep, date_string, tod_string);
    //call parse_date with first string
    date_type d = parse_undelimited_date<date_type>(date_string);
    //call parse_time_duration with remaining string
    time_duration td = parse_undelimited_time_duration<time_duration>(tod_string);
    //construct a time
    return time_type(d, td);
  }
    static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) {
      // offset is difference (in 100-nanoseconds) from
      // 1970-Jan-01 to 1601-Jan-01
      boost::uint64_t c1 = 27111902;
      boost::uint64_t c2 = 3577643008UL; // 'UL' removes compiler warnings
      const boost::uint64_t OFFSET = (c1 << 32) + c2;

      boost::uint64_t filetime = ft.dwHighDateTime;
      filetime = filetime << 32;
      filetime += ft.dwLowDateTime;
      filetime -= OFFSET;
      // filetime now holds 100-nanoseconds since 1970-Jan-01

      // microseconds -- static casts supress warnings
      boost::uint32_t sub_sec = static_cast<boost::uint32_t>((filetime % 10000000) / 10);

      std::time_t t = static_cast<time_t>(filetime / 10000000); // seconds since epoch
      
      std::tm curr, *curr_ptr = 0;
      if (tz == LOCAL) {
        curr_ptr = c_time::localtime(&t, &curr);
      }
      else {
        curr_ptr = c_time::gmtime(&t, &curr);
      }
      date_type d(curr_ptr->tm_year + 1900,
                  curr_ptr->tm_mon + 1,
                  curr_ptr->tm_mday);

      //The following line will adjusts the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = static_cast<int>(resolution_traits_type::res_adjust()/1000000);

      time_duration_type td(curr_ptr->tm_hour,
                            curr_ptr->tm_min,
                            curr_ptr->tm_sec,
                            sub_sec * adjust);
                            //st.wMilliseconds * adjust);
      return time_type(d,td);

    }
Example #8
0
    static time_type create_time(timeval* tv) {
      time_t t = tv->tv_sec;
      boost::uint32_t fs = tv->tv_usec;
      ::std::time(&t); 
      tm* curr = localtime(&t);
      date_type d(curr->tm_year + 1900, 
		  curr->tm_mon + 1, 
		  curr->tm_mday);
      //The following line will adjusts the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = resolution_traits_type::res_adjust()/1000000;

      time_duration_type td(curr->tm_hour,
			    curr->tm_min,
                            curr->tm_sec,
			    fs*adjust);
      return time_type(d,td);
      
    }
Example #9
0
    static time_type create_time(time_converter converter)
    {
#ifdef BOOST_HAS_GETTIMEOFDAY
      timeval tv;
      gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux.
      std::time_t t = tv.tv_sec;
      pdalboost::uint32_t sub_sec = tv.tv_usec;
#elif defined(BOOST_HAS_FTIME)
      winapi::file_time ft;
      winapi::get_system_time_as_file_time(ft);
      uint64_t micros = winapi::file_time_to_microseconds(ft); // it will not wrap, since ft is the current time
                                                               // and cannot be before 1970-Jan-01
      std::time_t t = static_cast<std::time_t>(micros / 1000000UL); // seconds since epoch
      // microseconds -- static casts suppress warnings
      pdalboost::uint32_t sub_sec = static_cast<pdalboost::uint32_t>(micros % 1000000UL);
#else
#error Internal Boost.DateTime error: BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK is defined, however neither gettimeofday nor FILETIME support is detected.
#endif

      std::tm curr;
      std::tm* curr_ptr = converter(&t, &curr);
      date_type d(static_cast< typename date_type::year_type::value_type >(curr_ptr->tm_year + 1900),
                  static_cast< typename date_type::month_type::value_type >(curr_ptr->tm_mon + 1),
                  static_cast< typename date_type::day_type::value_type >(curr_ptr->tm_mday));

      //The following line will adjust the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = static_cast< int >(resolution_traits_type::res_adjust() / 1000000);

      time_duration_type td(static_cast< typename time_duration_type::hour_type >(curr_ptr->tm_hour),
                            static_cast< typename time_duration_type::min_type >(curr_ptr->tm_min),
                            static_cast< typename time_duration_type::sec_type >(curr_ptr->tm_sec),
                            sub_sec * adjust);

      return time_type(d,td);
    }
  inline
  time_type time_from_ftime(const FILETIME& ft){
    typedef typename time_type::date_type date_type;
    typedef typename time_type::date_duration_type date_duration_type;
    typedef typename time_type::time_duration_type time_duration_type;

    /* OFFSET is difference between 1970-Jan-01 & 1601-Jan-01 
     * in 100-nanosecond intervals */
    uint64_t c1 = 27111902UL; 
    uint64_t c2 = 3577643008UL; // issues warning without 'UL'
    const uint64_t OFFSET = (c1 << 32) + c2;
    const long sec_pr_day = 86400; // seconds per day

    uint64_t filetime = ft.dwHighDateTime;
    filetime <<= 32;
    filetime += ft.dwLowDateTime;
    filetime -= OFFSET; // filetime is now 100-nanos since 1970-Jan-01

    uint64_t sec = filetime / 10000000;
#if defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
    uint64_t sub_sec = (filetime % 10000000) * 100; // nanoseconds
#else
    uint64_t sub_sec = (filetime % 10000000) / 10; // truncate to microseconds
#endif

    // split sec into usable chunks: days, hours, minutes, & seconds
    long _d = sec / sec_pr_day;
    long tmp = sec % sec_pr_day;
    long _h = tmp / 3600; // sec_pr_hour
    tmp %= 3600;
    long _m = tmp / 60; // sec_pr_min
    tmp %= 60;
    long _s = tmp; // seconds

    date_duration_type dd(_d);
    date_type d = date_type(1970, Jan, 01) + dd;
    return time_type(d, time_duration_type(_h, _m, _s, sub_sec));
  }
 //! Convert a utc time to local time
 static time_type utc_to_local(const time_type& t)
 {
   date_type time_t_start_day(1970,1,1);
   time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0));
   if (t < time_t_start_time) {
     throw std::out_of_range("Cannot convert dates prior to Jan 1, 1970");
   }
   date_duration_type dd = t.date() - time_t_start_day;
   time_duration_type td = t.time_of_day();
   std::time_t t2 = dd.days()*86400 + td.hours()*3600 + td.minutes()*60 + td.seconds();
   std::tm tms, *tms_ptr;
   tms_ptr = c_time::localtime(&t2, &tms);
   //tms_ptr = std::localtime(&t2);
   date_type d(static_cast<unsigned short>(tms_ptr->tm_year + 1900),
               static_cast<unsigned short>(tms_ptr->tm_mon + 1),
               static_cast<unsigned short>(tms_ptr->tm_mday));
   time_duration_type td2(tms_ptr->tm_hour,
                          tms_ptr->tm_min,
                          tms_ptr->tm_sec,
                          t.time_of_day().fractional_seconds());
   
   return time_type(d,td2);
 }
Example #12
0
    static time_type create_time(FILETIME& ft) {
      // offset is difference (in 100-nanoseconds) from
      // 1970-Jan-01 to 1601-Jan-01
      boost::uint64_t c1 = 27111902;
      boost::uint64_t c2 = 3577643008UL; // 'UL' removes compiler warnings
      const boost::uint64_t OFFSET = (c1 << 32) + c2;

      boost::uint64_t filetime = ft.dwHighDateTime;
      filetime = filetime << 32;
      filetime += ft.dwLowDateTime;
      filetime -= OFFSET; 
      // filetime now holds 100-nanoseconds since 1970-Jan-01

      boost::uint32_t sub_sec = (filetime % 10000000) / 10; // microseconds
     
      time_t t;
      ::std::time(&t); 
      tm* curr = localtime(&t);
      date_type d(curr->tm_year + 1900, 
                  curr->tm_mon + 1, 
                  curr->tm_mday);

      //The following line will adjusts the fractional second tick in terms
      //of the current time system.  For example, if the time system
      //doesn't support fractional seconds then res_adjust returns 0
      //and all the fractional seconds return 0.
      int adjust = resolution_traits_type::res_adjust()/1000000;

      time_duration_type td(curr->tm_hour,
                            curr->tm_min,
                            curr->tm_sec,
                            sub_sec * adjust);
                            //st.wMilliseconds * adjust);
      return time_type(d,td);
      
    }
Example #13
0
 static time_type local_time(boost::shared_ptr<time_zone_type> tz_ptr)
 {
   typedef typename time_type::utc_time_type utc_time_type;
   utc_time_type utc_time = second_clock<utc_time_type>::universal_time();
   return time_type(utc_time, tz_ptr);
 }
	high_resolution_timer::high_resolution_timer(io_service& io_service)
		: m_expiration_time(time_type())
		, m_io_service(io_service)
		, m_expired(true)
	{
	}
 /**
  * @return An absolute time value representing the stream buffer's expiry
  * time.
  */
 time_type expires_at() const
 {
   return timer_service_
     ? timer_service_->expires_at(timer_implementation_)
     : time_type();
 }
Example #16
0
 timer::time_type timer::expires_at() const
 {
     return time_type();
 }