Fix the other part from #231
This commit is contained in:
parent
78a5053b22
commit
ed2739829f
|
@ -176,16 +176,7 @@ fn get_datetime_tuple_fold(py: Python, dt: &PyDateTime) -> Py<PyTuple> {
|
|||
|
||||
#[pyfunction]
|
||||
fn datetime_from_timestamp(py: Python, ts: f64, tz: Option<&PyTzInfo>) -> PyResult<Py<PyDateTime>> {
|
||||
let timestamp: PyObject = ts.to_object(py);
|
||||
let tzi: PyObject = match tz {
|
||||
Some(t) => t.to_object(py),
|
||||
None => py.None(),
|
||||
};
|
||||
|
||||
let args = PyTuple::new(py, &[timestamp, tzi]);
|
||||
let kwargs = PyDict::new(py);
|
||||
|
||||
PyDateTime::from_timestamp(py, &args.to_object(py), &kwargs.to_object(py))
|
||||
PyDateTime::from_timestamp(py, ts, tz)
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use conversion::ToPyObject;
|
||||
use err::PyResult;
|
||||
use ffi;
|
||||
use ffi::PyDateTimeAPI;
|
||||
use ffi::{PyDateTime_Check, PyDateTime_DateTimeType};
|
||||
#[cfg(Py_3_6)]
|
||||
use ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD};
|
||||
use ffi::{
|
||||
PyDateTime_DATE_GET_HOUR, PyDateTime_DATE_GET_MICROSECOND, PyDateTime_DATE_GET_MINUTE,
|
||||
PyDateTime_DATE_GET_SECOND,
|
||||
|
@ -18,14 +21,11 @@ use ffi::{
|
|||
};
|
||||
use ffi::{PyDateTime_TZInfoType, PyTZInfo_Check};
|
||||
use ffi::{PyDateTime_TimeType, PyTime_Check};
|
||||
use object::PyObject;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
#[cfg(Py_3_6)]
|
||||
use ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD};
|
||||
|
||||
use instance::Py;
|
||||
use object::PyObject;
|
||||
use python::{Python, ToPyPointer};
|
||||
use std::os::raw::c_int;
|
||||
use std::ptr;
|
||||
use types::PyTuple;
|
||||
|
||||
// Traits
|
||||
|
@ -125,14 +125,23 @@ impl PyDateTime {
|
|||
|
||||
pub fn from_timestamp(
|
||||
py: Python,
|
||||
args: &PyObject,
|
||||
kwargs: &PyObject,
|
||||
timestamp: f64,
|
||||
time_zone_info: Option<&PyTzInfo>,
|
||||
) -> PyResult<Py<PyDateTime>> {
|
||||
let timestamp: PyObject = timestamp.to_object(py);
|
||||
|
||||
let time_zone_info: PyObject = match time_zone_info {
|
||||
Some(time_zone_info) => time_zone_info.to_object(py),
|
||||
None => py.None(),
|
||||
};
|
||||
|
||||
let args = PyTuple::new(py, &[timestamp, time_zone_info]);
|
||||
|
||||
unsafe {
|
||||
let ptr = (PyDateTimeAPI.DateTime_FromTimestamp)(
|
||||
PyDateTimeAPI.DateTimeType,
|
||||
args.as_ptr(),
|
||||
kwargs.as_ptr(),
|
||||
ptr::null_mut(),
|
||||
);
|
||||
Py::from_owned_ptr_or_err(py, ptr)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use err::{self, PyErr, PyResult};
|
|||
use ffi;
|
||||
use instance::PyObjectWithToken;
|
||||
use object::PyObject;
|
||||
use python::{Python, ToPyPointer, IntoPyPointer};
|
||||
use python::{IntoPyPointer, Python, ToPyPointer};
|
||||
use std;
|
||||
use std::{cmp, collections, hash, mem};
|
||||
use types::{PyList, PyObjectRef};
|
||||
|
@ -277,7 +277,7 @@ mod test {
|
|||
use python::Python;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use types::dict::IntoPyDict;
|
||||
use types::{PyDict, PyTuple, PyList};
|
||||
use types::{PyDict, PyList, PyTuple};
|
||||
use ObjectProtocol;
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue