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>&
137 std::locale savedlocale = is.getloc();
141 boost::posix_time::time_input_facet *input_facet =
142 new boost::posix_time::time_input_facet();
143 input_facet->set_iso_extended_format();
144 std::locale iso8601_loc(std::locale::classic(), input_facet);
146 is.imbue(iso8601_loc);
152 std::char_traits<char>::int_type tztype = is.peek();
153 if(tztype != std::char_traits<char>::eof())
160 else if (tztype ==
'-' || tztype ==
'+')
163 if (is.rdbuf()->in_avail() >= 4)
167 is.read(&inchars[0], 4);
168 for (
int i=0; i < 4; ++i)
169 if (inchars[i] <
'0' || inchars[i] >
'9')
170 is.setstate(std::ios::failbit);
176 std::istringstream valueis(inchars);
183 boost::posix_time::time_duration d(offset/100, offset%100, 0);
188 is.setstate(std::ios::failbit);
193 is.setstate(std::ios::failbit);
202 throw std::runtime_error(
"Failed to parse timestamp");
204 catch (
const std::exception& e)
206 is.imbue(savedlocale);
210 is.imbue(savedlocale);
219 #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.
Definition: CoreMetadata.cpp:40
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
Xerces-C modern C++ wrapper.
Definition: Base.h:53