Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/5896.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`PyDate::from_timestamp` argument is now a `f64` (the Python API expects a float and not an integer)
2 changes: 1 addition & 1 deletion pytests/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn get_date_tuple<'py>(d: &Bound<'py, PyDate>) -> PyResult<Bound<'py, PyTuple>>
}

#[pyfunction]
fn date_from_timestamp(py: Python<'_>, timestamp: i64) -> PyResult<Bound<'_, PyDate>> {
fn date_from_timestamp(py: Python<'_>, timestamp: f64) -> PyResult<Bound<'_, PyDate>> {
PyDate::from_timestamp(py, timestamp)
}

Expand Down
2 changes: 1 addition & 1 deletion pytests/stubs/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TzClass(tzinfo):
def tzname(self, _dt: datetime | None, /) -> str: ...
def utcoffset(self, _dt: datetime | None, /) -> timedelta: ...

def date_from_timestamp(timestamp: int) -> date: ...
def date_from_timestamp(timestamp: float) -> date: ...
def datetime_from_timestamp(ts: float, tz: tzinfo | None = None) -> datetime: ...
def get_date_tuple(d: date) -> tuple: ...
def get_datetime_tuple(dt: datetime) -> tuple: ...
Expand Down
4 changes: 2 additions & 2 deletions src/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl PyDate {
/// Construct a `datetime.date` from a POSIX timestamp
///
/// This is equivalent to `datetime.date.fromtimestamp`
pub fn from_timestamp(py: Python<'_>, timestamp: i64) -> PyResult<Bound<'_, PyDate>> {
pub fn from_timestamp(py: Python<'_>, timestamp: f64) -> PyResult<Bound<'_, PyDate>> {
#[cfg(not(Py_LIMITED_API))]
{
let time_tuple = PyTuple::new(py, [timestamp])?;
Expand Down Expand Up @@ -925,7 +925,7 @@ mod tests {
#[cfg_attr(target_arch = "wasm32", ignore)] // DateTime import fails on wasm for mysterious reasons
fn test_date_fromtimestamp() {
Python::attach(|py| {
let dt = PyDate::from_timestamp(py, 100).unwrap();
let dt = PyDate::from_timestamp(py, 100.).unwrap();
py_run!(
py,
dt,
Expand Down
Loading