Finish replacing utcnow (#9260)

refs #9186
This commit is contained in:
Alex Gaynor 2023-07-18 08:37:00 -04:00 committed by GitHub
parent 0bb2fe81a1
commit 10813b0bed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -134,10 +134,10 @@ Then we generate the certificate itself:
... ).serial_number(
... x509.random_serial_number()
... ).not_valid_before(
... datetime.datetime.utcnow()
... datetime.datetime.now(datetime.timezone.utc)
... ).not_valid_after(
... # Our certificate will be valid for 10 days
... datetime.datetime.utcnow() + datetime.timedelta(days=10)
... datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=10)
... ).add_extension(
... x509.SubjectAlternativeName([x509.DNSName(u"localhost")]),
... critical=False,

View file

@ -540,11 +540,16 @@ pub(crate) fn py_to_datetime(
}
pub(crate) fn datetime_now(py: pyo3::Python<'_>) -> pyo3::PyResult<asn1::DateTime> {
let datetime_module = py.import(pyo3::intern!(py, "datetime"))?;
let utc = datetime_module
.getattr(pyo3::intern!(py, "timezone"))?
.getattr(pyo3::intern!(py, "utc"))?;
py_to_datetime(
py,
py.import(pyo3::intern!(py, "datetime"))?
datetime_module
.getattr(pyo3::intern!(py, "datetime"))?
.call_method0(pyo3::intern!(py, "utcnow"))?,
.call_method1(pyo3::intern!(py, "now"), (utc,))?,
)
}