39 #ifndef OME_XML_MODEL_PRIMITIVES_TIMESTAMP_H 40 #define OME_XML_MODEL_PRIMITIVES_TIMESTAMP_H 46 #include <boost/date_time/posix_time/posix_time.hpp> 113 template<
class charT,
class traits>
114 inline std::basic_ostream<charT,traits>&
115 operator<< (std::basic_ostream<charT,traits>& os,
118 return os << boost::posix_time::to_iso_extended_string(static_cast<Timestamp::value_type>(timestamp))
129 template<
class charT,
class traits>
130 inline std::basic_istream<charT,traits>&
134 std::istream::sentry s(is);
140 std::locale savedlocale = is.getloc();
144 boost::posix_time::time_input_facet *input_facet =
145 new boost::posix_time::time_input_facet();
146 input_facet->set_iso_extended_format();
147 std::locale iso8601_loc(std::locale::classic(), input_facet);
149 is.imbue(iso8601_loc);
155 std::char_traits<char>::int_type tztype = is.peek();
156 if(tztype != std::char_traits<char>::eof())
163 else if (tztype ==
'-' || tztype ==
'+')
166 if (is.rdbuf()->in_avail() >= 4)
169 std::string inchars(4,
' ');
170 is.read(&inchars[0], 4);
171 for (std::string::const_iterator i = inchars.begin();
174 if (*i < '0' || *i >
'9')
175 is.setstate(std::ios::failbit);
181 std::istringstream valueis(inchars);
188 boost::posix_time::time_duration d(offset/100, offset%100, 0);
193 is.setstate(std::ios::failbit);
198 is.setstate(std::ios::failbit);
207 throw std::runtime_error(
"Failed to parse timestamp");
209 catch (
const std::exception& e)
211 is.imbue(savedlocale);
215 is.imbue(savedlocale);
225 #endif // OME_XML_MODEL_PRIMITIVES_TIMESTAMP_H An ISO-8601 timestamp.
Definition: Timestamp.h:66
value_type value
The POSIX time (at least microsecond precision).
Definition: Timestamp.h:103
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:472
boost::posix_time::ptime value_type
POSIX time is the underlying time representation.
Definition: Timestamp.h:69