Author: wyoung
Date: Sat Dec 22 00:09:31 2007
New Revision: 2013
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2013&view=rev
Log:
- Added DateTime::is_now() method to return true if 'now' member is true
and all the other values are zero. Calling this instead of just
testing 'now' directly guards against the possibility of instantiating
DateTime with the default ctor then assigning values to its data
members separately. Only other way we could do this is hide all the
data members behind accessors so we can reset 'now' flag when setting
the other values, but it's too much overhead for such simple classes.
- Expanded test_datetime to check this.
Modified:
trunk/lib/datetime.cpp
trunk/lib/datetime.h
trunk/test/test_datetime.cpp
Modified: trunk/lib/datetime.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.cpp?rev=2013&r1=2012&r2=2013&view=diff
==============================================================================
--- trunk/lib/datetime.cpp (original)
+++ trunk/lib/datetime.cpp Sat Dec 22 00:09:31 2007
@@ -74,7 +74,7 @@
std::ostream& operator <<(std::ostream& os, const DateTime& dt)
{
- if (dt.now) {
+ if (dt.is_now()) {
return os << "NOW()";
}
else {
@@ -177,7 +177,7 @@
int DateTime::compare(const DateTime& other) const
{
- if (now && other.now) {
+ if (is_now() && other.is_now()) {
return 0;
}
else {
@@ -195,7 +195,7 @@
DateTime::operator time_t() const
{
- if (now) {
+ if (is_now()) {
// Many factors combine to make it almost impossible for this
// case to return the same value as you'd get if you used this
// in a query. But, you gotta better idea than to return the
@@ -245,6 +245,16 @@
now = false;
}
+
+bool
+DateTime::is_now() const
+{
+ return now &&
+ year == 0 && month == 0 && day == 0 &&
+ hour == 0 && minute == 0 && second == 0;
+}
+
+
} // end namespace mysqlpp
Modified: trunk/lib/datetime.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.h?rev=2013&r1=2012&r2=2013&view=diff
==============================================================================
--- trunk/lib/datetime.h (original)
+++ trunk/lib/datetime.h Sat Dec 22 00:09:31 2007
@@ -198,6 +198,17 @@
/// \brief Parse a MySQL date and time string into this object.
MYSQLPP_EXPORT cchar* convert(cchar*);
+ /// \brief Returns true if 'now' member is true and all other
+ /// members are zero.
+ ///
+ /// Can't just test 'now' because you can create the object with
+ /// the default ctor (giving a "now" value) and then assign values
+ /// to its data members later, which should make it "not now". We
+ /// could do without this by hiding all the data members behind
+ /// accessors which can reset the "now" flag when setting other
+ /// values, but it's too simple a class to bother.
+ bool is_now() const;
+
/// Convert to time_t
operator time_t() const;
};
Modified: trunk/test/test_datetime.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/test_datetime.cpp?rev=2013&r1=2012&r2=2013&view=diff
==============================================================================
--- trunk/test/test_datetime.cpp (original)
+++ trunk/test/test_datetime.cpp Sat Dec 22 00:09:31 2007
@@ -125,6 +125,9 @@
failures += test(0, 0, 0, 0, 0, 0);
failures += test(1, 2, 3, 4, 5, 6);
failures += test_ostream_form(DateTime(), "NOW()", "DateTime");
+ DateTime dt;
+ dt.year = 2007;
+ failures += test_ostream_form(dt, "2007-00-00 00:00:00", "DateTime");
return failures;
}
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits