hikyuu2/libs/hikyuu_python/_Datetime.cpp

57 lines
1.8 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _Datetime.cpp
*
* Created on: 2012-9-27
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/serialization/Datetime_serialization.h>
#include "pickle_support.h"
using namespace boost::python;
using namespace hku;
bool (*eq)(const Datetime&, const Datetime&) = operator==;
bool (*ne)(const Datetime&, const Datetime&) = operator!=;
bool (*gt)(const Datetime&, const Datetime&) = operator>;
bool (*lt)(const Datetime&, const Datetime&) = operator<;
bool (*ge)(const Datetime&, const Datetime&) = operator>=;
bool (*le)(const Datetime&, const Datetime&) = operator<=;
void export_Datetime() {
2017-09-23 19:51:22 +08:00
docstring_options doc_options(false, true, false);
2015-01-07 01:26:14 +08:00
class_<Datetime>("Datetime")
.def(init<unsigned long long>())
.def(init<const std::string&>())
.def(self_ns::str(self))
.add_property("year", &Datetime::year)
.add_property("month", &Datetime::month)
.add_property("day", &Datetime::day)
.add_property("hour", &Datetime::hour)
.add_property("minute", &Datetime::minute)
.add_property("second", &Datetime::second)
2015-01-07 01:26:14 +08:00
.add_property("number", &Datetime::number)
.def("toString", &Datetime::toString)
.def("min", &Datetime::min).staticmethod("min")
.def("max", &Datetime::max).staticmethod("max")
2015-01-07 01:26:14 +08:00
.def("now", &Datetime::now).staticmethod("now")
2016-04-14 01:36:53 +08:00
//不支持boost.date
//.def("date", &Datetime::date)
2015-01-07 01:26:14 +08:00
.def("__eq__", eq)
.def("__ne__", ne)
.def("__gt__", gt)
.def("__lt__", lt)
.def("__ge__", ge)
.def("__le__", le)
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<Datetime>())
#endif
;
2017-09-23 19:51:22 +08:00
def("getDateRange", getDateRange, (arg("start"), arg("end")));
2015-01-07 01:26:14 +08:00
}