Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JDate_t.hh
Go to the documentation of this file.
1#ifndef __JDB_JDATE_T__
2#define __JDB_JDATE_T__
3
4#include <istream>
5#include <ostream>
6
7#include "Jeep/JDate.hh"
8#include "Jeep/JTime.hh"
9
11
12
13/**
14 * \author mdejong
15 */
16namespace JDATABASE {}
17namespace JPP { using namespace JDATABASE; }
18
19namespace JDATABASE {
20
22 using JLANG::JTYPELIST;
23
24 typedef JEEP::JDate<'/'> JDate_t; //!< type defintion of date according database format
25 typedef JEEP::JTime<':'> JTime_t; //!< type defintion of time according database format
26
27
28 /**
29 * Date and time.
30 */
32 public JDate_t,
33 public JTime_t,
34 public JMultiComparable<JDateAndTime_t, JTYPELIST<JDate_t, JTime_t>::typelist>
35 {
36 /**
37 * Separation character.
38 */
39 static const char SEPARATOR = '-';
40
41
42 /**
43 * Default constructor;
44 */
47
48
49 /**
50 * Read date and time from input stream.
51 *
52 * \param in input stream
53 * \param object date and time
54 * \return input stream
55 */
56 friend inline std::istream& operator>>(std::istream& in, JDateAndTime_t& object)
57 {
58 in >> static_cast<JDate_t&>(object);
59
60 if (in.get() == (int) SEPARATOR) {
61 in >> static_cast<JTime_t&>(object);
62 }
63
64 return in;
65 }
66
67
68 /**
69 * Write date and time to output stream.
70 *
71 * \param out output stream
72 * \param object date and time
73 * \return output stream
74 */
75 friend inline std::ostream& operator<<(std::ostream& out, const JDateAndTime_t& object)
76 {
77 out << static_cast<const JDate_t&>(object);
78 out << SEPARATOR;
79 out << static_cast<const JTime_t&>(object);
80
81 return out;
82 }
83 };
84
85
86 /**
87 * Date and time.
88 */
90 public JDateAndTime_t
91 {
92 /**
93 * Default constructor;
94 */
97
98
99 /**
100 * Read date and time from input stream.
101 *
102 * \param in input stream
103 * \param object date and time
104 * \return input stream
105 */
106 friend inline std::istream& operator>>(std::istream& in, JDateAndTimeUS_t& object)
107 {
108 using namespace std;
109 using namespace JPP;
110
111 object = JDateAndTimeUS_t();
112
113 while (isspace(in.peek())) { in.ignore(); }
114
115 const locale loc = in.imbue(locale(in.getloc(), new JWhiteSpacesFacet(in.getloc(), JDate_t::SEPARATOR)));
116
117 in >> object.month >> object.day >> object.year;
118
119 if (in.get() == (int) ' ') {
120
121 in.imbue(locale(in.getloc(), new JWhiteSpacesFacet(in.getloc(), JTime_t::SEPARATOR)));
122
123 in >> object.hour >> object.minute >> object.second;
124
125 if (in.get() == (int) ' ') {
126
127 string key;
128
129 in >> key;
130
131 if (key == "am" || key == "AM") {}
132 if (key == "pm" || key == "PM") { object.hour += 12; }
133 }
134 }
135
136 in.imbue(loc);
137
138 return in;
139 }
140 };
141}
142
143#endif
Auxiliary class to specify white space character(s) in currect locale.
char * loc(char *orig)
Auxiliary classes and methods for database I/O.
Definition JAHRS.hh:14
JEEP::JTime<':'> JTime_t
type defintion of time according database format
Definition JDate_t.hh:25
JEEP::JDate<'/'> JDate_t
type defintion of date according database format
Definition JDate_t.hh:24
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
friend std::istream & operator>>(std::istream &in, JDateAndTimeUS_t &object)
Read date and time from input stream.
Definition JDate_t.hh:106
JDateAndTimeUS_t()
Default constructor;.
Definition JDate_t.hh:95
friend std::istream & operator>>(std::istream &in, JDateAndTime_t &object)
Read date and time from input stream.
Definition JDate_t.hh:56
friend std::ostream & operator<<(std::ostream &out, const JDateAndTime_t &object)
Write date and time to output stream.
Definition JDate_t.hh:75
static const char SEPARATOR
Separation character.
Definition JDate_t.hh:39
JDateAndTime_t()
Default constructor;.
Definition JDate_t.hh:45
Auxiliary class for simple date.
Definition JDate.hh:40
static const char SEPARATOR
Separation character.
Definition JDate.hh:44
Auxiliary class for simple time.
Definition Jeep/JTime.hh:40
static const char SEPARATOR
Separation character.
Definition Jeep/JTime.hh:44
Template definition of auxiliary base class for composite data structures composed of base classes wi...
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351