summaryrefslogtreecommitdiff
path: root/src/py_times.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-05-04 13:41:23 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:38 -0400
commit0528a1e49a82221e63039abc7f759a43f4d4ffc9 (patch)
treee433db931847f003aef895ea255a2c541057bd3f /src/py_times.cc
parent96684b72ca367bfd4dbe2e45a9a66c56204eb533 (diff)
downloadfork-ledger-0528a1e49a82221e63039abc7f759a43f4d4ffc9.tar.gz
fork-ledger-0528a1e49a82221e63039abc7f759a43f4d4ffc9.tar.bz2
fork-ledger-0528a1e49a82221e63039abc7f759a43f4d4ffc9.zip
Added boost::optional support for using with Boost.Python.
Diffstat (limited to 'src/py_times.cc')
-rw-r--r--src/py_times.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/py_times.cc b/src/py_times.cc
index 578d887b..f509e0d0 100644
--- a/src/py_times.cc
+++ b/src/py_times.cc
@@ -9,6 +9,8 @@
#include <Python.h>
#include <datetime.h>
+// jww (2007-05-04): Convert time duration objects to PyDelta
+
namespace ledger {
using namespace boost::python;
@@ -29,7 +31,7 @@ struct date_from_python
static void* convertible(PyObject* obj_ptr)
{
PyDateTime_IMPORT;
- if(PyDate_Check(obj_ptr) || PyDateTime_Check(obj_ptr)) return obj_ptr;
+ if (PyDate_Check(obj_ptr)) return obj_ptr;
return 0;
}
@@ -48,15 +50,13 @@ typedef register_python_conversion<date, date_to_python, date_from_python>
date_python_conversion;
-typedef boost::posix_time::ptime datetime;
-
struct datetime_to_python
{
- static PyObject* convert(const datetime& moment)
+ static PyObject* convert(const moment_t& moment)
{
PyDateTime_IMPORT;
date dte = moment.date();
- datetime::time_duration_type tod = moment.time_of_day();
+ moment_t::time_duration_type tod = moment.time_of_day();
return PyDateTime_FromDateAndTime(dte.year(), dte.month(), dte.day(),
tod.hours(), tod.minutes(), tod.seconds(),
tod.total_microseconds() % 1000000);
@@ -81,19 +81,21 @@ struct datetime_from_python
int h = PyDateTime_DATE_GET_HOUR(obj_ptr);
int min = PyDateTime_DATE_GET_MINUTE(obj_ptr);
int s = PyDateTime_DATE_GET_SECOND(obj_ptr);
- datetime* moment = new datetime(date(y,m,d),
- datetime::time_duration_type(h, min, s));
+ moment_t* moment = new moment_t(date(y,m,d),
+ moment_t::time_duration_type(h, min, s));
data->convertible = (void*)moment;
}
};
-typedef register_python_conversion<datetime, datetime_to_python, datetime_from_python>
+typedef register_python_conversion<moment_t, datetime_to_python, datetime_from_python>
datetime_python_conversion;
void export_times()
{
date_python_conversion();
datetime_python_conversion();
+
+ python_optional<moment_t>();
}
} // namespace ledger