Fix duration overflow (#1150)
This commit is contained in:
parent
2e51e703c3
commit
8f3f693f20
@ -57,6 +57,8 @@ PyObject *gMgpSerializationError{nullptr}; // NOLINT(cppcoreguidelines-avo
|
||||
PyObject *gMgpAuthorizationError{nullptr}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
constexpr bool kStartGarbageCollection{true};
|
||||
constexpr auto kMicrosecondsInMillisecond{1000};
|
||||
constexpr auto kMicrosecondsInSecond{1000000};
|
||||
|
||||
// Returns true if an exception is raised
|
||||
bool RaiseExceptionFromErrorCode(const mgp_error error) {
|
||||
@ -2488,21 +2490,23 @@ py::Object MgpValueToPyObject(const mgp_value &value, PyGraph *py_graph) {
|
||||
}
|
||||
case MGP_VALUE_TYPE_LOCAL_TIME: {
|
||||
const auto &local_time = value.local_time_v->local_time;
|
||||
py::Object py_local_time(PyTime_FromTime(local_time.hour, local_time.minute, local_time.second,
|
||||
local_time.millisecond * 1000 + local_time.microsecond));
|
||||
py::Object py_local_time(
|
||||
PyTime_FromTime(local_time.hour, local_time.minute, local_time.second,
|
||||
local_time.millisecond * kMicrosecondsInMillisecond + local_time.microsecond));
|
||||
return py_local_time;
|
||||
}
|
||||
case MGP_VALUE_TYPE_LOCAL_DATE_TIME: {
|
||||
const auto &local_time = value.local_date_time_v->local_date_time.local_time;
|
||||
const auto &date = value.local_date_time_v->local_date_time.date;
|
||||
py::Object py_local_date_time(PyDateTime_FromDateAndTime(date.year, date.month, date.day, local_time.hour,
|
||||
local_time.minute, local_time.second,
|
||||
local_time.millisecond * 1000 + local_time.microsecond));
|
||||
py::Object py_local_date_time(PyDateTime_FromDateAndTime(
|
||||
date.year, date.month, date.day, local_time.hour, local_time.minute, local_time.second,
|
||||
local_time.millisecond * kMicrosecondsInMillisecond + local_time.microsecond));
|
||||
return py_local_date_time;
|
||||
}
|
||||
case MGP_VALUE_TYPE_DURATION: {
|
||||
const auto &duration = value.duration_v->duration;
|
||||
py::Object py_duration(PyDelta_FromDSU(0, 0, duration.microseconds));
|
||||
py::Object py_duration(PyDelta_FromDSU(0, duration.microseconds / kMicrosecondsInSecond,
|
||||
duration.microseconds % kMicrosecondsInSecond));
|
||||
return py_duration;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user