Add objects/datetime.rs
This commit is contained in:
parent
2b74cdbd57
commit
496b879525
|
@ -24,6 +24,7 @@ spin = "0.4.9"
|
|||
num-traits = "0.2.5"
|
||||
pyo3cls = { path = "pyo3cls", version = "=0.4.1" }
|
||||
mashup = "0.1.5"
|
||||
lazy_static = "1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
docmatic = "0.1.2"
|
||||
|
|
|
@ -129,6 +129,8 @@ extern crate spin;
|
|||
#[doc(hidden)]
|
||||
pub extern crate mashup;
|
||||
|
||||
#[macro_use] extern crate lazy_static;
|
||||
|
||||
#[cfg(not(Py_3))]
|
||||
mod ffi2;
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
use object::PyObject;
|
||||
use std::os::raw::c_int;
|
||||
use ffi::{PyDateTime_CAPI, PyDateTime_IMPORT};
|
||||
use python::{Python, ToPyPointer};
|
||||
use instance::Py;
|
||||
|
||||
pub struct PyDate(PyObject);
|
||||
pyobject_convert!(PyDate);
|
||||
pyobject_nativetype!(PyDate, PyDateTime_Date, PyDate_Check);
|
||||
|
||||
lazy_static! {
|
||||
static ref PyDateTimeAPI: PyDateTime_CAPI = unsafe { PyDateTime_IMPORT() };
|
||||
}
|
||||
|
||||
impl PyDate {
|
||||
pub fn new(py: Python, year: u32, month: u32, day: u32) -> Py<PyDate> {
|
||||
let y = year as c_int;
|
||||
let m = month as c_int;
|
||||
let d = day as c_int;
|
||||
|
||||
unsafe {
|
||||
let ptr = PyDateTimeAPI.Date_FromDate.unwrap()(y, m, d, PyDateTimeAPI.DateType);
|
||||
Py::from_owned_ptr_or_panic(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ mod exc_impl;
|
|||
|
||||
pub use self::boolobject::PyBool;
|
||||
pub use self::bytearray::PyByteArray;
|
||||
pub use self::datetime::{PyDate};
|
||||
pub use self::dict::PyDict;
|
||||
pub use self::floatob::PyFloat;
|
||||
pub use self::iterator::PyIterator;
|
||||
|
@ -185,6 +186,7 @@ pyobject_native_type_convert!(PyObjectRef, ffi::PyBaseObject_Type, ffi::PyObject
|
|||
|
||||
mod boolobject;
|
||||
mod bytearray;
|
||||
mod datetime;
|
||||
mod dict;
|
||||
pub mod exc;
|
||||
mod floatob;
|
||||
|
|
Loading…
Reference in New Issue