#ifndef __JDB_JDATE_T__ #define __JDB_JDATE_T__ #include #include #include "Jeep/JDate.hh" #include "Jeep/JTime.hh" #include "JLang/JMultiComparable.hh" /** * \author mdejong */ namespace JDATABASE {} namespace JPP { using namespace JDATABASE; } namespace JDATABASE { using JLANG::JMultiComparable; using JLANG::JTYPELIST; typedef JEEP::JDate<'/'> JDate_t; //!< type defintion of date according database format typedef JEEP::JTime<':'> JTime_t; //!< type defintion of time according database format /** * Date and time. */ struct JDateAndTime_t : public JDate_t, public JTime_t, public JMultiComparable::typelist> { /** * Separation character. */ static const char SEPARATOR = '-'; /** * Default constructor; */ JDateAndTime_t() {} /** * Read date and time from input stream. * * \param in input stream * \param object date and time * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JDateAndTime_t& object) { in >> static_cast(object); if (in.get() == (int) SEPARATOR) { in >> static_cast(object); } return in; } /** * Write date and time to output stream. * * \param out output stream * \param object date and time * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JDateAndTime_t& object) { out << static_cast(object); out << SEPARATOR; out << static_cast(object); return out; } }; /** * Date and time. */ struct JDateAndTimeUS_t : public JDateAndTime_t { /** * Default constructor; */ JDateAndTimeUS_t() {} /** * Read date and time from input stream. * * \param in input stream * \param object date and time * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JDateAndTimeUS_t& object) { using namespace std; using namespace JPP; object = JDateAndTimeUS_t(); while (isspace(in.peek())) { in.ignore(); } const locale loc = in.imbue(locale(in.getloc(), new JWhiteSpacesFacet(in.getloc(), JDate_t::SEPARATOR))); in >> object.month >> object.day >> object.year; if (in.get() == (int) ' ') { in.imbue(locale(in.getloc(), new JWhiteSpacesFacet(in.getloc(), JTime_t::SEPARATOR))); in >> object.hour >> object.minute >> object.second; if (in.get() == (int) ' ') { string key; in >> key; if (key == "am" || key == "AM") {} if (key == "pm" || key == "PM") { object.hour += 12; } } } in.imbue(loc); return in; } }; } #endif