Try to deal with varied forms of dates and times, and ease things like "I would like to specify a range of days in a particular format" (e.g. for bulk fetching), and such.
Note that this module is focused only on days, not on precise times. And, as a result (timezones), it may be a day off.
CONSIDER: making anything range-based be generators.
Class |
|
specific configuration for dateutil for dutch month and week names |
Function | date |
No summary |
Function | date |
No summary |
Function | date |
No summary |
Function | date |
No summary |
Function | date |
Given a larger interval, return a series of shorter intervals no larger than increment_days long. (currently first and last days overlap; TODO: parameter to control that) |
Function | date |
No summary |
Function | date |
No summary |
Function | days |
Given a start and end date, returns a list of all individual days in that range (including the last), as a datetime.date object. (Note that if you want something like this for pandas, it has its own date_range that may be nicer)... |
Function | find |
Tries to fish out date-like strings from free-form text. Not general-purpose - it's targeted at some specific fields we know have mainly/only contain dates, and have relatively well formatted dates, mostly to normalize those. |
Function | format |
Takes a single datetime object, calls strftime on it. |
Function | format |
Takes a list of datetime objects, calls format_date() on each of that list. |
Function | parse |
Try to parse a string as a date. |
Function | yyyy |
Given a datetime or date like datetime.date(2024, 1, 1), returns a string like '2024-01-01' (strftime('%Y-%m-%d') |
Function | _date |
Intended to normalzing date/datetime/date-as-string parameters into date objects. |
Constant | _MAAND |
regexp fragment to match most month spellings, English and Dutch |
Variable | _re |
Undocumented |
Variable | _re |
Undocumented |
Variable | _re |
Undocumented |
Parameters | |
yearnum:int | the year you want the first day of, e.g. 2024. If not given, defaults to the current year. |
monthnum:int | the year you want the first day of, e.g. 2024. If not given, defaults to the current month. (note that if you don't give month but do give year, you might get some behaviour you did not expect) |
Returns | |
The first day of the month in the given year, as a datetime.date |
Parameters | |
yearnum:int | the year you want the first day of, e.g. 2024. If not given, defaults to the current year. |
Returns | |
January first of the given year, as a datetime.date |
Parameters | |
yearnum:int | the year you want the first day of, e.g. 2024. If not given, defaults to the current year. |
Returns | |
January first of the given year, as a datetime.date |
Parameters | |
amount:float | Undocumented |
Returns | |
A date some amount of months ago from the day of calling this, as a datetime.date |
Given a larger interval, return a series of shorter intervals no larger than increment_days long. (currently first and last days overlap; TODO: parameter to control that)
Parameters | |
from | start of range. Takes a date object, a datetime object, or string to parse (using dateutil library; please do not use ambiguous formats like 02/02/11) |
to | end of range, inclusive |
increment | size of each range |
strftime | Undocumented |
Returns | |
a list of tuples, which are either
|
Parameters | |
amount:float | Undocumented |
Returns | |
A date some amount of months ago from the day of calling this, as a datetime.date |
Given a start and end date, returns a list of all individual days in that range (including the last), as a datetime.date object. (Note that if you want something like this for pandas, it has its own date_range that may be nicer)
For example: :
date_range( datetime.date(2022, 1, 29), datetime.date(2022, 2, 2) )
and :
date_range( '29 jan 2022', '2 feb 2022')
should both give: :
[ datetime.date(2022, 1, 29), datetime.date(2022, 1, 30), datetime.date(2022, 1, 31), datetime.date(2022, 2, 1), datetime.date(2022, 2, 2) ]
Parameters | |
from | start of range, as a date object, datetime object, or string to parse (using dateutil library) (please do not use formats like 02/02/11 and also expect the output to do what you want) |
to | end of range, inclusive |
strftime | Undocumented |
Returns | |
a list of datetime.date objects |
Tries to fish out date-like strings from free-form text. Not general-purpose - it's targeted at some specific fields we know have mainly/only contain dates, and have relatively well formatted dates, mostly to normalize those.
...because "try to find everthing, hope for the best" is likely to have false positives (identify things as dates that aren't) as well as false negatives (miss things that are ). CONSIDER: still, add such a freer mode in here anyway, just not as the default.
Currently looks only for three specific patterns:
- 1980-01-01
- 1 jan 1980
- jan 1 1980
...the latter two with both Dutch and English month naming.
Parameters | |
text:str | the string to find dates in |
Returns | |
two lists:
CONSIDER: also match objects so that we have positions? |
Takes a single datetime object, calls strftime on it.
Parameters | |
dt | a datetime obkect |
strftime | a string that tells strftime how to format the date Defaults to '%Y-%m-%d', which is a ISO8601-style YYYY-MM-DD thing |
Returns | |
date string, formatted that way |
Takes a list of datetime objects, calls format_date() on each of that list.
For example: :
format_date_range( date_range( datetime.date(2022, 1, 29), datetime.date(2022, 2, 2) ) )
would return: :
['2022-01-29', '2022-01-30', '2022-01-31', '2022-02-01', '2022-02-02']
Parameters | |
datelist | a list of datetime objects |
strftime | a string that tells strftime how to format the date (see also format_date ) |
Returns | |
a list of formatted date strings |
Try to parse a string as a date.
Mostly just calls dateutil.parser.parse(), a library that deals with more varied date formats ...but we have told it a litte more about Dutch, not just English. TODO: add French, there is some early legal text in French.
We try to be a little more robust here - and will try to return None instead of raising an exception (but no promises).
Parameters | |
text:str | Takes a string that you know contains just a date |
as | return as date, not datetime. |
exception | if invalid, return None rather than raise a ValueError |
Returns | |
that date as a datetime (or date, if you prefer), or None |
Given a datetime or date like datetime.date(2024, 1, 1), returns a string like '2024-01-01' (strftime('%Y-%m-%d')
Parameters | |
day:datetime.date | Undocumented |
Intended to normalzing date/datetime/date-as-string parameters into date objects.
Parameters | |
a | date as a date object, datetime object, or string to parse (using dateutil library) |
Returns | |
date object |