This commit is contained in:
konstin 2018-09-27 01:11:18 +02:00
parent 05874d3f1a
commit 78a5053b22
2 changed files with 6 additions and 5 deletions

View File

@ -25,10 +25,8 @@ fn get_date_tuple(py: Python, d: &PyDate) -> Py<PyTuple> {
}
#[pyfunction]
fn date_from_timestamp(py: Python, ts: i64) -> PyResult<Py<PyDate>> {
let timestamp = ts.to_object(py);
let args = PyTuple::new(py, &[timestamp]);
PyDate::from_timestamp(py, &args.to_object(py))
fn date_from_timestamp(py: Python, timestamp: i64) -> PyResult<Py<PyDate>> {
PyDate::from_timestamp(py, timestamp)
}
#[pyfunction]

View File

@ -26,6 +26,7 @@ use ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD};
use instance::Py;
use python::{Python, ToPyPointer};
use types::PyTuple;
// Traits
pub trait PyDateAccess {
@ -66,7 +67,9 @@ impl PyDate {
}
}
pub fn from_timestamp(py: Python, args: &PyObject) -> PyResult<Py<PyDate>> {
pub fn from_timestamp(py: Python, timestamp: i64) -> PyResult<Py<PyDate>> {
let args = PyTuple::new(py, &[timestamp]);
unsafe {
let ptr = (PyDateTimeAPI.Date_FromTimestamp)(PyDateTimeAPI.DateType, args.as_ptr());
Py::from_owned_ptr_or_err(py, ptr)