13 #ifdef HAVE_SYS_TYPES_H
14 #include <sys/types.h>
47 assign(a_year,a_month,a_day,a_hour,a_minute,a_second);
61 struct tm* tm_ptr = 0;
65 throw(
ERROR(errno,
"Could not retrieve current time"));
66 tm_ptr = localtime(&t);
68 throw(
ERROR(errno,
"Could not convert current time to local time"));
69 m_year = tm_ptr->tm_year + 1900;
71 m_day = tm_ptr->tm_mday;
102 if ((a_year < 0) || (a_year > 9999)) {
111 if ((a_month > 12) || (a_month < 1)) {
120 if ((a_day > 31) || (a_day < 1)) {
129 if ((a_hour < 0) || (a_hour > 23)) {
138 if ((a_minute < 0) || (a_minute > 59)) {
147 if ((a_second < 0) || (a_second > 59)) {
172 TRY_nomem(es =
"Invalid timestamp string: \"");
179 TRY_nomem(bes =
"Parse error converting string to timestamp: \"");
190 TRY(l_year = str,ies);
195 if (a_s.size() == 4) {
208 TRY(l_month = str,ies);
213 if (a_s.size() == 7) {
214 assign(l_year,l_month,1,0,0,0);
220 if (a_s.size() >= 10)
226 TRY(l_day = str,ies);
231 if (a_s.size() == 10) {
232 assign(l_year,l_month,l_day,0,0,0);
238 if (a_s.size() >= 13)
244 TRY(l_hour = str,ies);
249 if (a_s.size() == 13) {
250 assign(l_year,l_month,l_day,l_hour,0,0);
256 if (a_s.size() >= 15)
262 TRY(l_minute = str,ies);
267 if (a_s.size() == 15) {
268 assign(l_year,l_month,l_day,l_hour,l_minute,0);
274 if (a_s.size() == 17)
280 TRY(l_second = str,ies);
285 assign(l_year,l_month,l_day,l_hour,l_minute,l_second);
315 TRY_nomem(es =
"Could not create timestamp string");
321 TRY_nomem(es = bes +
", error converting year");
333 TRY_nomem(es = bes +
", error converting month");
345 TRY_nomem(es = bes +
", error converting day");
357 TRY_nomem(es = bes +
", error converting hour");
367 TRY_nomem(es = bes +
", error converting minute");
377 TRY_nomem(es = bes +
", error converting second");
472 value = (
str(r) < a_t.
str(r));
484 value = (
str(r) > a_t.
str(r));
496 value = (
str(r) == a_t.
str(r));
507 if (a_s.size() < 4) {
510 if (!isdigit(a_s[0])) {
513 if (!isdigit(a_s[1])) {
516 if (!isdigit(a_s[2])) {
519 if (!isdigit(a_s[3])) {
529 if ((i < 0) || (i > 9999)) {
532 if (a_s.size() == 4) {
536 if (a_s.size() < 7) {
542 if (!isdigit(a_s[5])) {
545 if (!isdigit(a_s[6])) {
555 if ((i < 1) || (i > 12)) {
558 if (a_s.size() == 7) {
562 if (a_s.size() < 10) {
568 if (!isdigit(a_s[8])) {
571 if (!isdigit(a_s[9])) {
581 if ((i < 1) || (i > 31)) {
584 if (a_s.size() == 10) {
588 if (a_s.size() < 13) {
591 if (a_s[10] !=
'.') {
594 if (!isdigit(a_s[11])) {
597 if (!isdigit(a_s[12])) {
607 if ((i < 0) || (i > 23)) {
610 if (a_s.size() == 13) {
614 if (a_s.size() < 15) {
617 if (!isdigit(a_s[13])) {
620 if (!isdigit(a_s[14])) {
630 if ((i < 0) || (i > 59)) {
633 if (a_s.size() == 15) {
637 if (a_s.size() < 17) {
640 if (!isdigit(a_s[15])) {
643 if (!isdigit(a_s[16])) {
653 if ((i < 0) || (i > 59)) {
656 if (a_s.size() == 17) {
void clear(void)
Clear the timestamp.
resolution_type resolution(void) const
Return the timestamp resolution.
int year(void) const
Return the timestamp year.
int day(void) const
Return the timestamp day.
An extended string class.
void reset(void)
Erase and reinitialize.
resolution_type m_resolution
int month(void) const
Return the timestamp month.
char left_fillchar(const char a_char)
Set the fill character used to padd the left side of a formatted string.
bool operator<(const timestamp &a_t) const
Comparison.
bool operator>(const timestamp &a_t) const
Comparison.
void assign(const timestamp &a_t)
Set the timestamp to the value of another timestamp.
value_type fmt_str(void)
Generate a formatted string.
int second(void) const
Return the timestamp second.
void resolution(resolution_type a_r)
Set the timestamp resolution.
void set(void)
Set the timestamp to the current time and date.
bool is_timestamp(const std::string &a_s)
Return true if the string is a valid timestamp.
timestamp & operator=(const timestamp &a_t)
Assignment.
const std::string make_str_(const int a_resolution) const
Generate a string.
size_type width(const size_type a_l)
Set the width of a formatted string.
int hour(void) const
Return the timestamp hour.
alignment align(const alignment a_alignment)
Set the alignment used for formatted strings.
bool operator==(const timestamp &a_t) const
Comparison.
const std::string str(void) const
Generate a string.
int minute(void) const
Return the timestamp minute.