Author: wyoung
Date: Fri Nov 10 23:50:15 2006
New Revision: 1331
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1331&view=rev
Log:
DateTime can now be initialized from a time_t, or converted implicitly
to time_t. Patch by Korolyov Ilya <[EMAIL PROTECTED]>, with style mods by
me.
Modified:
trunk/lib/datetime.cpp
trunk/lib/datetime.h
Modified: trunk/lib/datetime.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.cpp?rev=1331&r1=1330&r2=1331&view=diff
==============================================================================
--- trunk/lib/datetime.cpp (original)
+++ trunk/lib/datetime.cpp Fri Nov 10 23:50:15 2006
@@ -171,6 +171,32 @@
}
}
+DateTime::operator time_t() const
+{
+ struct tm tm;
+ tm.tm_sec = second;
+ tm.tm_min = minute;
+ tm.tm_hour = hour;
+ tm.tm_mday = day;
+ tm.tm_mon = month - (tiny_int)1;
+ tm.tm_year = year - 1900;
+
+ return mktime(&tm);
+};
+
+DateTime::DateTime(time_t t)
+{
+ struct tm tm;
+ localtime_r(&t, &tm);
+
+ year = tm.tm_year + 1900;
+ month = tm.tm_mon + 1;
+ day = tm.tm_mday;
+ hour = tm.tm_hour;
+ minute = tm.tm_min;
+ second = tm.tm_sec;
+}
+
} // end namespace mysqlpp
Modified: trunk/lib/datetime.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/datetime.h?rev=1331&r1=1330&r2=1331&view=diff
==============================================================================
--- trunk/lib/datetime.h (original)
+++ trunk/lib/datetime.h Fri Nov 10 23:50:15 2006
@@ -177,6 +177,9 @@
convert(str.c_str());
}
+ /// \brief Initialize object from a time_t
+ DateTime(time_t t);
+
/// \brief Compare this datetime to another.
///
/// Returns < 0 if this datetime is before the other, 0 of they are
@@ -188,6 +191,9 @@
/// \brief Parse a MySQL date and time string into this object.
cchar* convert(cchar*);
+
+ /// Convert to time_t
+ operator time_t() const;
};
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits