Exemplo n.º 1
0
 //! Put time into an ostream 
 static void time_put(const time_type& t, 
                      ostream_type& os)
 {
   date_type d = t.date();
   os << d << " "; //TODO: fix the separator here.
   duration_formatter::duration_put(t.time_of_day(), os);
   
 } // time_to_ostream    
Exemplo n.º 2
0
    OutItrT put(OutItrT a_next, 
                std::ios_base& a_ios, 
                char_type a_fill, 
                const time_type& a_time) const 
    {
      if (a_time.is_special()) { 
        return do_put_special(a_next, a_ios, a_fill, 
                              a_time.date().as_special());
      }
      string_type format(m_format);
      string_type frac_str;
      if (format.find(seconds_with_fractional_seconds_format)) {
        // replace %s with %S.nnn 
        frac_str = 
          fractional_seconds_as_string(a_time.time_of_day(), false);
        char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point();
        
        string_type replace_string(seconds_format);
        replace_string += sep;
        replace_string += frac_str;
        boost::algorithm::replace_all(format, 
                                      seconds_with_fractional_seconds_format, 
                                      replace_string);
      }
      if (format.find(fractional_seconds_format)) {
        // replace %f with nnnnnnn
        if (!frac_str.size()) {
          frac_str = fractional_seconds_as_string(a_time.time_of_day(), false);
        }
        boost::algorithm::replace_all(format,
                                      fractional_seconds_format, 
                                      frac_str);
      }

      if (format.find(fractional_seconds_or_none_format)) {
        // replace %F with nnnnnnn or nothing if fs == 0
        frac_str = 
          fractional_seconds_as_string(a_time.time_of_day(), true);
        if (frac_str.size()) {
          char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point();
          string_type replace_string;
          replace_string += sep;
          replace_string += frac_str;
          boost::algorithm::replace_all(format,
                                        fractional_seconds_or_none_format, 
                                        replace_string);
        }
        else {
          boost::algorithm::erase_all(format,
                                      fractional_seconds_or_none_format);
        }
      }

      return do_put_tm(a_next, a_ios, a_fill, 
                       to_tm(a_time), format);
    }
Exemplo n.º 3
0
 //! Put time into an ostream 
 static void time_put(const time_type& t, 
                      ostream_type& os)
 {
   date_type d = t.date();
   os << d;
   if(!d.is_infinity() && !d.is_not_a_date())
   {
     os << " "; //TODO: fix the separator here.
     duration_formatter::duration_put(t.time_of_day(), os);
   }
   
 } // time_to_ostream    
Exemplo n.º 4
0
 //! Get the offset to UTC given a local time
 static time_duration_type local_to_utc_offset(const time_type& t, 
                                               date_time::dst_flags dst=date_time::calculate) 
 { 
   switch (dst) {
   case is_dst:
     return utc_offset_rules::local_to_utc_base_offset() - dst_rules::dst_offset();
   case not_dst:
     return utc_offset_rules::local_to_utc_base_offset();
   case calculate:
     time_is_dst_result res = 
       dst_rules::local_is_dst(t.date(), t.time_of_day());
     switch(res) {
     case is_in_dst:      return utc_offset_rules::local_to_utc_base_offset() - dst_rules::dst_offset();
     case is_not_in_dst:      return utc_offset_rules::local_to_utc_base_offset();
     case ambiguous:          return utc_offset_rules::local_to_utc_base_offset();
     case invalid_time_label: throw std::out_of_range("Time label invalid");
     }
   }  
   throw std::out_of_range("Time label invalid");
 }
 //! Get the offset to UTC given a local time
 static time_duration_type local_to_utc_offset(const time_type& t, 
                                               date_time::dst_flags dst=date_time::calculate) 
 {
   switch (dst) {
   case is_dst:
     return utc_offset_rules::local_to_utc_base_offset() - dst_rules::dst_offset();
   case not_dst:
     return utc_offset_rules::local_to_utc_base_offset();
   case calculate:
     time_is_dst_result res = 
       dst_rules::local_is_dst(t.date(), t.time_of_day());
     switch(res) {
     case is_in_dst:      return utc_offset_rules::local_to_utc_base_offset() - dst_rules::dst_offset();
     case is_not_in_dst:      return utc_offset_rules::local_to_utc_base_offset();
     case ambiguous:          return utc_offset_rules::local_to_utc_base_offset();
     case invalid_time_label: break;
     }
   }
   lslboost::throw_exception(std::out_of_range("Time label invalid"));
   BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_duration_type(not_a_date_time)); // should never reach
 }
 //! 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);
 }