| |
- isodatetime(d)
- converts a date to ISO format.
This function returns the datetime.datetime
object as an ISO date string of the form
YYYY-MM-DDTHH:MM:SS.
parameters:
d -- a datetime.datetime object
returns:
a string.
Here are some examples:
>>> isodatetime(datetime.datetime(2008, 10, 20, 11, 19, 30))
'2008-10-20T11:19:30'
- isolsl(d)
- converts a date to ISO-like format used in "ls -l".
This function returns the datetime.datetime
object as an ISO date string of the form
YYYY-MM-DD HH:MM.
parameters:
d -- a datetime.datetime object
returns:
a string.
Here are some examples:
>>> isolsl(datetime.datetime(2008, 10, 20, 11, 19, 30))
'2008-10-20 11:19'
- my_strptime(st, format_)
- a strptime replacement that checks with several locales.
- parse_isodate(str_)
- parse an ISO date without a time.
This function parses an ISO date (without time) and returns
a datetime.datetime object. An ISO date
(at least here) has the form YYYY-MM-DD,
an example is 2006-10-09.
parameters:
str_ -- the string to parse
returns:
a datetime.datetime object
Here are some examples:
>>> parse_isodate("2006-10-09")
datetime.datetime(2006, 10, 9, 0, 0)
>>> parse_isodate("2007-11-09")
datetime.datetime(2007, 11, 9, 0, 0)
>>> parse_isodate("2007-11-09x")
Traceback (most recent call last):
...
ValueError: unconverted data remains: x
- parse_isodatetime(str_)
- parse an ISO date.
This function parses an ISO date and returns
a datetime.datetime object. An ISO date
(at least here) has the form YYYY-MM-DDTHH:MM:SS,
an example is 2006-10-09T10:33:09.
parameters:
str_ -- the string to parse
returns:
a datetime.datetime object
Here are some examples:
>>> parse_isodatetime("2006-10-09T10:33:09")
datetime.datetime(2006, 10, 9, 10, 33, 9)
>>> parse_isodatetime("2006-10-09T10:33:09x")
Traceback (most recent call last):
...
ValueError: unconverted data remains: x
>>> parse_isodatetime("2006-99-09T10:33:09")
Traceback (most recent call last):
...
ValueError: time data '2006-99-09T10:33:09' does not match format '%Y-%m-%dT%H:%M:%S'
- parse_lsl_date(str_, year=None)
- parse a date produced by "ls -l".
Here are some examples:
>>> parse_lsl_date("2009-03-16 10:26")
datetime.datetime(2009, 3, 16, 10, 26)
>>> parse_lsl_date("Oct 9 10:42", 2016)
datetime.datetime(2016, 10, 9, 10, 42)
>>> parse_lsl_date("Oct 9 10:42",2010)
datetime.datetime(2010, 10, 9, 10, 42)
>>> parse_lsl_date("Oct 9 10:42x",2010)
Traceback (most recent call last):
...
ValueError: lsl date 'Oct 9 10:42x' not parsable
- parse_lsl_isodate(str_)
- parse an ISO-like date produced from ls -l.
This function parses a date in the form
YYYY-MM-DD HH:MM, which is a date that the "ls -l"
command may produce. It returns a datetime.datetime object.
parameters:
str_ -- the string to parse
returns:
a datetime.datetime object
Here are some examples:
>>> parse_lsl_isodate("2009-03-16 10:26")
datetime.datetime(2009, 3, 16, 10, 26)
>>> parse_lsl_isodate("2009-03-16 10:26")
datetime.datetime(2009, 3, 16, 10, 26)
>>> parse_lsl_isodate("Oct 9 10:42")
Traceback (most recent call last):
...
ValueError: time data 'Oct 9 10:42' does not match format '%Y-%m-%d %H:%M'
- parse_lsl_shortdate(st, year=None)
- parse a possibly yearless date produced from ls -l.
This function parses a date that was produced by "ls -l". It returns a
datetime.datetime object. Note that this function sets the year to the
current year if not specified differently by it's second parameter. Note
also, that 29th of February could be invalid for the current year. The
function currently tries the default locale and the de_DE locale.
parameters:
st -- the string to parse
year -- the optional year, an integer
returns:
a datetime.datetime object
Here are some examples:
>>> parse_lsl_shortdate("Oct 9 10:42",2016)
datetime.datetime(2016, 10, 9, 10, 42)
>>> parse_lsl_shortdate("Oct 9 10:42",2005)
datetime.datetime(2005, 10, 9, 10, 42)
>>> parse_lsl_shortdate("Oct 9 2007")
datetime.datetime(2007, 10, 9, 0, 0)
>>> parse_lsl_shortdate("29. Jul 10:42", 2007)
datetime.datetime(2007, 7, 29, 10, 42)
>>> parse_lsl_shortdate("Oct 9 10:42b",2005)
Traceback (most recent call last):
...
ValueError: time data 'Oct 9 10:42b' does not match any of the known formats: ['%b %d %H:%M %Y', '%d. %b %H:%M %Y', '%d. %b %Y', '%b %d %Y'] for locales ['default', 'de_DE.UTF-8']
|