Skip to content
Merged
24 changes: 21 additions & 3 deletions Lib/_pydatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,11 @@ def fromisocalendar(cls, year, week, day):

@classmethod
def strptime(cls, date_string, format):
"""Parse string according to the given date format (like time.strptime())."""
"""Parse string according to the given date format (like time.strptime()).

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
"""
import _strptime
return _strptime._strptime_datetime_date(cls, date_string, format)

Expand Down Expand Up @@ -1109,6 +1113,8 @@ def strftime(self, format):
Format using strftime().

Example: "%d/%m/%Y, %H:%M:%S"
For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
"""
return _wrap_strftime(self, format, self.timetuple())

Expand Down Expand Up @@ -1456,8 +1462,13 @@ def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold
return self

@classmethod

def strptime(cls, date_string, format):
"""Parse string according to the given time format (like time.strptime())."""
"""Parse string according to the given time format (like time.strptime()).

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
"""
import _strptime
return _strptime._strptime_datetime_time(cls, date_string, format)

Expand Down Expand Up @@ -1650,6 +1661,9 @@ def fromisoformat(cls, time_string):
def strftime(self, format):
"""Format using strftime(). The date part of the timestamp passed
to underlying strftime should not be used.

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
"""
# The year must be >= 1000 else Python's strftime implementation
# can raise a bogus exception.
Expand Down Expand Up @@ -2198,7 +2212,11 @@ def __str__(self):

@classmethod
def strptime(cls, date_string, format):
"""Parse string according to the given date and time format (like time.strptime())."""
"""Parse string according to the given time format (like time.strptime()).

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
"""
import _strptime
return _strptime._strptime_datetime_datetime(cls, date_string, format)

Expand Down
25 changes: 20 additions & 5 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3468,12 +3468,15 @@ datetime.date.strptime
/

Parse string according to the given date format (like time.strptime()).

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
[clinic start generated code]*/

static PyObject *
datetime_date_strptime_impl(PyTypeObject *type, PyObject *string,
PyObject *format)
/*[clinic end generated code: output=454d473bee2d5161 input=001904ab34f594a1]*/
/*[clinic end generated code: output=454d473bee2d5161 input=31d57bb789433e99]*/
{
PyObject *result;

Expand Down Expand Up @@ -3608,11 +3611,14 @@ datetime.date.strftime
Format using strftime().

Example: "%d/%m/%Y, %H:%M:%S".

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
[clinic start generated code]*/

static PyObject *
datetime_date_strftime_impl(PyObject *self, PyObject *format)
/*[clinic end generated code: output=6529b70095e16778 input=72af55077e606ed8]*/
/*[clinic end generated code: output=6529b70095e16778 input=b6fd4a2ded27b557]*/
{
/* This method can be inherited, and needs to call the
* timetuple() method appropriate to self's class.
Expand Down Expand Up @@ -4711,12 +4717,15 @@ datetime.time.strptime
/

Parse string according to the given time format (like time.strptime()).

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
[clinic start generated code]*/

static PyObject *
datetime_time_strptime_impl(PyTypeObject *type, PyObject *string,
PyObject *format)
/*[clinic end generated code: output=ae05a9bc0241d3bf input=6d0f263a5f94d78d]*/
/*[clinic end generated code: output=ae05a9bc0241d3bf input=82ba425ecacc54aa]*/
{
PyObject *result;

Expand Down Expand Up @@ -4891,11 +4900,14 @@ datetime.time.strftime
Format using strftime().

The date part of the timestamp passed to underlying strftime should not be used.

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
[clinic start generated code]*/

static PyObject *
datetime_time_strftime_impl(PyDateTime_Time *self, PyObject *format)
/*[clinic end generated code: output=10f65af20e2a78c7 input=541934a2860f7db5]*/
/*[clinic end generated code: output=10f65af20e2a78c7 input=c4a5bbecd798654b]*/
{
PyObject *result;
PyObject *tuple;
Expand Down Expand Up @@ -5787,12 +5799,15 @@ datetime.datetime.strptime
/

Parse string according to the given date and time format (like time.strptime()).

For a list of supported format codes, see the documentation:
https://docs.python.org/3/library/datetime.html#format-codes
[clinic start generated code]*/

static PyObject *
datetime_datetime_strptime_impl(PyTypeObject *type, PyObject *string,
PyObject *format)
/*[clinic end generated code: output=af2c2d024f3203f5 input=d7597c7f5327117b]*/
/*[clinic end generated code: output=af2c2d024f3203f5 input=ef7807589f1d50e7]*/
{
PyObject *result;

Expand Down
27 changes: 21 additions & 6 deletions Modules/clinic/_datetimemodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading