improve doctrings for datetime parsing methods
This commit is contained in:
parent
e005ead49b
commit
91ebaba14c
|
@ -925,7 +925,33 @@ class date:
|
|||
self._day, self._year)
|
||||
|
||||
def strftime(self, fmt):
|
||||
"Format using strftime()."
|
||||
"""strftime(fmt) -> date_string
|
||||
|
||||
Return a string from the date parsed according to format.
|
||||
Format codes referring to hours, minutes or seconds will see 0 values.
|
||||
|
||||
Args:
|
||||
format: representation of date_string using format codes.
|
||||
|
||||
Commonly used format codes:
|
||||
%Y Year with century as a decimal number.
|
||||
%m Month as a decimal number [01,12].
|
||||
%d Day of the month as a decimal number [01,31].
|
||||
%H Hour (24-hour clock) as a decimal number [00,23].
|
||||
%M Minute as a decimal number [00,59].
|
||||
%S Second as a decimal number [00,61].
|
||||
%z Time zone offset from UTC.
|
||||
%a Locale's abbreviated weekday name.
|
||||
%A Locale's full weekday name.
|
||||
%b Locale's abbreviated month name.
|
||||
%B Locale's full month name.
|
||||
%c Locale's appropriate date and time representation.
|
||||
%I Hour (12-hour clock) as a decimal number [01,12].
|
||||
%p Locale's equivalent of either AM or PM.
|
||||
|
||||
Returns:
|
||||
date_string: String representation of the date
|
||||
"""
|
||||
return _wrap_strftime(self, fmt, self.timetuple())
|
||||
|
||||
def __format__(self, fmt):
|
||||
|
@ -1445,8 +1471,25 @@ class time:
|
|||
|
||||
|
||||
def strftime(self, fmt):
|
||||
"""Format using strftime(). The date part of the timestamp passed
|
||||
to underlying strftime should not be used.
|
||||
"""strftime(fmt) -> time_string
|
||||
|
||||
Return a string of the time parsed according to format.
|
||||
Format codes referring to year, month or days will see 0 values.
|
||||
|
||||
Args:
|
||||
fmt: representation of time using format codes.
|
||||
|
||||
Commonly used format codes:
|
||||
%H Hour (24-hour clock) as a decimal number [00,23].
|
||||
%M Minute as a decimal number [00,59].
|
||||
%S Second as a decimal number [00,61].
|
||||
%z Time zone offset from UTC.
|
||||
%c Locale's appropriate date and time representation.
|
||||
%I Hour (12-hour clock) as a decimal number [01,12].
|
||||
%p Locale's equivalent of either AM or PM.
|
||||
|
||||
Returns:
|
||||
time_string: String representation of time
|
||||
"""
|
||||
# The year must be >= 1000 else Python's strftime implementation
|
||||
# can raise a bogus exception.
|
||||
|
@ -1944,7 +1987,38 @@ class datetime(date):
|
|||
|
||||
@classmethod
|
||||
def strptime(cls, date_string, format):
|
||||
'string, format -> new datetime parsed from a string (like time.strptime()).'
|
||||
"""strptime(date_string, format) -> datetime object
|
||||
|
||||
Return a datetime object from the date_string,
|
||||
parsed according to format.
|
||||
|
||||
Args:
|
||||
date_string: string containing the date.
|
||||
format: representation of datetime using format codes.
|
||||
|
||||
Commonly used format codes:
|
||||
%Y Year with century as a decimal number.
|
||||
%m Month as a decimal number [01,12].
|
||||
%d Day of the month as a decimal number [01,31].
|
||||
%H Hour (24-hour clock) as a decimal number [00,23].
|
||||
%M Minute as a decimal number [00,59].
|
||||
%S Second as a decimal number [00,61].
|
||||
%z Time zone offset from UTC.
|
||||
%a Locale's abbreviated weekday name.
|
||||
%A Locale's full weekday name.
|
||||
%b Locale's abbreviated month name.
|
||||
%B Locale's full month name.
|
||||
%c Locale's appropriate date and time representation.
|
||||
%I Hour (12-hour clock) as a decimal number [01,12].
|
||||
%p Locale's equivalent of either AM or PM.
|
||||
|
||||
Returns:
|
||||
Datetime object
|
||||
|
||||
Raises:
|
||||
ValueError: If the date_string and format can’t be parsed by
|
||||
time.strptime() or if it returns a value which isn’t a time tuple.
|
||||
"""
|
||||
import _strptime
|
||||
return _strptime._strptime_datetime(cls, date_string, format)
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Improve docstring of :class:`datetime` methods :func:`strftime` and
|
||||
:func:`strptime`. Enhanced by Edison Abahurire.
|
Loading…
Reference in New Issue