hikyuu2/hikyuu_pywrap/_TimeDelta.cpp

191 lines
5.4 KiB
C++
Raw Normal View History

2019-12-15 01:25:00 +08:00
/*
* _TimeDelta.cpp
*
* Copyright (C) 2019 hikyuu.org
*
* Created on: 2019-12-14
* Author: fasiondog
*/
#include <hikyuu/serialization/TimeDelta_serialization.h>
2023-12-27 02:16:10 +08:00
#include "pybind_utils.h"
2019-12-15 01:25:00 +08:00
using namespace hku;
2023-12-26 18:25:50 +08:00
namespace py = pybind11;
2019-12-15 01:25:00 +08:00
2019-12-24 02:15:37 +08:00
double (TimeDelta::*TimeDelta_div_1)(TimeDelta) const = &TimeDelta::operator/;
TimeDelta (TimeDelta::*TimeDelta_div_2)(double) const = &TimeDelta::operator/;
2019-12-25 02:45:24 +08:00
TimeDelta (TimeDelta::*TimeDelta_pos)() const = &TimeDelta::operator+;
TimeDelta (TimeDelta::*TimeDelta_neg)() const = &TimeDelta::operator-;
2023-12-26 18:25:50 +08:00
void export_TimeDelta(py::module& m) {
2023-12-27 02:16:10 +08:00
py::class_<TimeDelta>(m, "TimeDelta",
2023-12-26 18:25:50 +08:00
R"(时间时长,用于时间计算。可通过以下方式构建:
2020-06-29 00:24:53 +08:00
- datetime.timedelta TimdeDelta(timedelta实例)
- TimeDelta(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0)
- -99999999 <= days <= 99999999
- -100000 <= hours <= 100000
- -100000 <= minutes <= 100000
- -8639900 <= seconds <= 8639900
- -86399000000 <= milliseconds <= 86399000000
- -86399000000 <= microseconds <= 86399000000
使使
Days, Hours, Minutes, Seconds, Milliseconds, Microseconds)")
2023-12-27 02:16:10 +08:00
.def(py::init<>())
.def(py::init<int64_t, int64_t, int64_t, int64_t, int64_t, int64_t>(), py::arg("days") = 0,
py::arg("hours") = 0, py::arg("minutes") = 0, py::arg("seconds") = 0,
py::arg("milliseconds") = 0, py::arg("microseconds") = 0)
2020-06-29 00:24:53 +08:00
.def("__str__", &TimeDelta::str)
.def("__repr__", &TimeDelta::repr)
2020-06-29 00:24:53 +08:00
2023-12-27 02:16:10 +08:00
.def_property_readonly("days", &TimeDelta::days, "天数 [-99999999, 99999999]")
.def_property_readonly("hours", &TimeDelta::hours, "小时数 [0, 23]")
.def_property_readonly("minutes", &TimeDelta::minutes, "分钟数 [0, 59]")
.def_property_readonly("seconds", &TimeDelta::seconds, "秒数 [0, 59]")
.def_property_readonly("milliseconds", &TimeDelta::milliseconds, "毫秒数 [0, 999]")
.def_property_readonly("microseconds", &TimeDelta::microseconds, "微秒数 [0, 999]")
.def_property_readonly("ticks", &TimeDelta::ticks, "同总微秒数")
2020-06-29 00:24:53 +08:00
.def("isNegative", &TimeDelta::isNegative, R"(isNegative(self)
:rtype: bool)")
.def("total_days", &TimeDelta::total_days, R"(total_days(self)
:rtype: float)")
.def("total_hours", &TimeDelta::total_hours, R"(total_hours(self)
:rtype: float)")
.def("total_minutes", &TimeDelta::total_minutes, R"(total_minutes(self)
:rtype: float)")
.def("total_seconds", &TimeDelta::total_seconds, R"(total_seconds(self)
:rtype: float)")
.def("total_milliseconds", &TimeDelta::total_milliseconds, R"(total_milliseconds(self)
:rtype: float)")
.def("max", &TimeDelta::max, R"(max()
:return: TimeDelta(99999999, 23, 59, 59, 999, 999))")
.def("min", &TimeDelta::min, R"(min()
:return: TimeDelta(-99999999, 0, 0, 0, 0, 0))")
.def("resolution", &TimeDelta::resolution, R"(resolution()
:return: TimeDelta(0, 0, 0, 0, 0, 1))")
2020-07-10 00:23:33 +08:00
.def("max_ticks", &TimeDelta::maxTicks, R"(max_ticks()
2020-06-29 00:24:53 +08:00
ticks
:rtype: int)")
2020-07-10 00:23:33 +08:00
.def("min_ticks", &TimeDelta::minTicks, R"(min_ticks()
2020-06-29 00:24:53 +08:00
ticks
:rtype: int)")
2020-07-10 00:23:33 +08:00
.def("from_ticks", &TimeDelta::fromTicks, R"(from_ticks(ticks)
2020-06-29 00:24:53 +08:00
使 ticks
:param int ticks:
:rtype: TimeDelta)")
2023-12-27 02:16:10 +08:00
.def(py::self == py::self)
.def(py::self != py::self)
.def(py::self >= py::self)
.def(py::self <= py::self)
.def(py::self > py::self)
.def(py::self < py::self)
.def(-py::self)
.def(+py::self)
.def(py::self + py::self)
.def(py::self - py::self)
.def(py::self % py::self)
.def(py::self * float())
2019-12-19 02:32:06 +08:00
2019-12-24 02:15:37 +08:00
.def("__abs__", &TimeDelta::abs)
.def("__rmul__", &TimeDelta::operator*)
.def("__truediv__", TimeDelta_div_1)
.def("__truediv__", TimeDelta_div_2)
2019-12-26 01:12:40 +08:00
.def("__floordiv__", &TimeDelta::floorDiv)
2019-12-18 02:04:54 +08:00
2023-12-27 02:16:10 +08:00
DEF_PICKLE(TimeDelta);
2023-12-27 02:16:10 +08:00
m.def("Days", Days, R"(Days(days)
2020-06-29 00:24:53 +08:00
TimeDelta
:param int days: [-99999999, 99999999]
:rtype: TimeDelta)");
2023-12-27 02:16:10 +08:00
m.def("Hours", Hours, R"(Hours(hours)
2020-06-29 00:24:53 +08:00
TimeDelta
:param int hours:
:rtype: TimeDelta)");
2023-12-27 02:16:10 +08:00
m.def("Minutes", Minutes, R"(Minutes(mins)
2020-06-29 00:24:53 +08:00
TimeDelta
:param int mins:
:rtype: TimeDelta)");
2023-12-27 02:16:10 +08:00
m.def("Seconds", Seconds, R"(Seconds(secs)
2020-06-29 00:24:53 +08:00
TimeDelta
:param int secs:
:rtype: TimeDelta)");
2023-12-27 02:16:10 +08:00
m.def("Milliseconds", Milliseconds, R"(Milliseconds(milliseconds)
2020-06-29 00:24:53 +08:00
TimeDelta
:param int milliseconds:
:rtype: TimeDelta)");
2023-12-27 02:16:10 +08:00
m.def("Microseconds", Microseconds, R"(Microseconds(microsecs)
2020-06-29 00:24:53 +08:00
TimeDelta
:param int microsecs:
:rtype: TimeDelta)");
2019-12-15 01:25:00 +08:00
}