39 #ifndef OME_XML_MODEL_PRIMITIVES_TIMESTAMP_H 40 #define OME_XML_MODEL_PRIMITIVES_TIMESTAMP_H 47 #include <boost/date_time/posix_time/posix_time.hpp> 112 template<
class charT,
class traits>
113 inline std::basic_ostream<charT,traits>&
114 operator<< (std::basic_ostream<charT,traits>& os,
117 return os << boost::posix_time::to_iso_extended_string(static_cast<Timestamp::value_type>(timestamp))
128 template<
class charT,
class traits>
129 inline std::basic_istream<charT,traits>&
133 std::istream::sentry s(is);
139 std::locale savedlocale = is.getloc();
143 boost::posix_time::time_input_facet *input_facet =
144 new boost::posix_time::time_input_facet();
145 input_facet->set_iso_extended_format();
146 std::locale iso8601_loc(std::locale::classic(), input_facet);
148 is.imbue(iso8601_loc);
154 std::char_traits<char>::int_type tztype = is.peek();
155 if(tztype != std::char_traits<char>::eof())
162 else if (tztype ==
'-' || tztype ==
'+')
165 if (is.rdbuf()->in_avail() >= 4)
168 std::string inchars(4,
' ');
169 is.read(&inchars[0], 4);
170 for (
const auto& i : inchars)
171 if (i < '0' || i >
'9')
172 is.setstate(std::ios::failbit);
178 std::istringstream valueis(inchars);
185 boost::posix_time::time_duration d(offset/100, offset%100, 0);
190 is.setstate(std::ios::failbit);
195 is.setstate(std::ios::failbit);
204 throw std::runtime_error(
"Failed to parse timestamp");
206 catch (
const std::exception& e)
208 is.imbue(savedlocale);
212 is.imbue(savedlocale);
222 #endif // OME_XML_MODEL_PRIMITIVES_TIMESTAMP_H An ISO-8601 timestamp.
Definition: Timestamp.h:65
value_type value
The POSIX time (at least microsecond precision).
Definition: Timestamp.h:102
Timestamp()
Construct a Timestamp (defaults to current UTC time).
Definition: Timestamp.cpp:50
Open Microscopy Environment C++ implementation.
std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &is, Color &color)
Set Color from input stream.
Definition: Color.h:478
boost::posix_time::ptime value_type
POSIX time is the underlying time representation.
Definition: Timestamp.h:68