~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.cc

  • Committer: Monty Taylor
  • Date: 2009-03-05 02:06:48 UTC
  • mfrom: (907.1.8 trunk-with-temporal)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090305020648-7jk1gie4lqsi22g8
Merged from Jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
#endif
46
46
#include "drizzled/temporal_format.h"
47
47
 
 
48
#include <ostream>
 
49
#include <iomanip>
48
50
#include <vector>
49
51
#include <string.h>
50
52
 
991
993
/*
992
994
 * Comparison operators between two Timestamps
993
995
 */
994
 
bool Date::operator==(const Timestamp& rhs)
 
996
bool Timestamp::operator==(const Timestamp& rhs)
995
997
{
996
998
  return (_epoch_seconds == rhs._epoch_seconds);
997
999
}
998
 
bool Date::operator!=(const Timestamp& rhs)
 
1000
bool Timestamp::operator!=(const Timestamp& rhs)
999
1001
{
1000
1002
  return ! (*this == rhs);
1001
1003
}
1002
 
bool Date::operator<(const Timestamp& rhs)
 
1004
bool Timestamp::operator<(const Timestamp& rhs)
1003
1005
{
1004
1006
  return (_epoch_seconds < rhs._epoch_seconds);
1005
1007
}
1006
 
bool Date::operator<=(const Timestamp& rhs)
 
1008
bool Timestamp::operator<=(const Timestamp& rhs)
1007
1009
{
1008
1010
  return (_epoch_seconds <= rhs._epoch_seconds);
1009
1011
}
1010
 
bool Date::operator>(const Timestamp& rhs)
 
1012
bool Timestamp::operator>(const Timestamp& rhs)
1011
1013
{
1012
1014
  return ! (*this < rhs);
1013
1015
}
1014
 
bool Date::operator>=(const Timestamp& rhs)
 
1016
bool Timestamp::operator>=(const Timestamp& rhs)
1015
1017
{
1016
1018
  return ! (*this <= rhs);
1017
1019
}
1018
1020
 
 
1021
/**
 
1022
 * Push the contents of the timestamp into the output stream
 
1023
 * as a formatted Timestamp value.
 
1024
 *
 
1025
 * @TODO This unfortunately fails in a weird way...even with std::noskipws, 
 
1026
 * the output stream only reads up to the space in the string... :(
 
1027
 */
 
1028
std::ostream& operator<<(std::ostream& os, const Timestamp& subject)
 
1029
{
 
1030
  return os << subject.years() << '-' 
 
1031
            << std::setw(2) << std::setfill('0') << subject.months() << '-'
 
1032
            << std::setw(2) << std::setfill('0') << subject.days() << ' '
 
1033
            << std::setw(2) << std::setfill('0') << subject.hours() << ':'
 
1034
            << std::setw(2) << std::setfill('0') << subject.minutes() << ':'
 
1035
            << std::setw(2) << std::setfill('0') << subject.seconds();
 
1036
}
 
1037
 
1019
1038
bool Time::from_string(const char *from, size_t from_len)
1020
1039
{
1021
1040
  /*
1428
1447
 
1429
1448
bool Timestamp::is_valid() const
1430
1449
{
1431
 
  return in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds);
 
1450
  return DateTime::is_valid() 
 
1451
      && in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds);
1432
1452
}
1433
1453
 
1434
1454
bool MicroTimestamp::is_valid() const
1435
1455
{
1436
 
  return in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds)
 
1456
  return Timestamp::is_valid()
1437
1457
      && (_useconds <= UINT32_C(999999));
1438
1458
}
1439
1459
 
1440
1460
bool NanoTimestamp::is_valid() const
1441
1461
{
1442
 
  return in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds)
 
1462
  return Timestamp::is_valid()
1443
1463
      && (_useconds <= UINT32_C(999999))
1444
1464
      && (_nseconds <= UINT32_C(999999999));
1445
1465
}