getdate¶
The getdate
method returns a date for a given expression, specifying the date by its position inside a time span which can be of a month or a year.
[1]:
from bizdays import Calendar
cal = Calendar.load(filename='ANBIMA.cal')
The desired date is the 15th day of May 2002.
The expression is 15th day
, year is 2002 and month is 5.
[2]:
cal.getdate('15th day', 2002, 5)
[2]:
datetime.date(2002, 5, 15)
If the month is omited the reference is the year of 2002.
[3]:
cal.getdate('15th day', 2002)
[3]:
datetime.date(2002, 1, 15)
In the expression 15th day
:
15th
is the positionday
is the desired date that in this case is the current date.
The expression accepts first
, second
, third
, 1st
, 2nd
, 3rd
, [n]th
, and last
as valid positions and
day
for regular days inside time spanbizday
for business days inside time spanweekdays:
sun
,mon
,tue
,wed
,thu
,fri
,sat
Here it returns the last day and the last business day of 2006.
[4]:
cal.getdate(['last day', 'last bizday'], 2006)
[4]:
[datetime.date(2006, 12, 31), datetime.date(2006, 12, 29)]
The first and last Monday of 2006.
[5]:
cal.getdate(['first mon', 'last mon'], 2006)
[5]:
[datetime.date(2006, 1, 2), datetime.date(2006, 12, 25)]
Using date postions as a reference¶
A day can be used as a reference, for example, the first Monday before the 30th day of July 2006.
[6]:
cal.getdate('last mon before 30th day', 2006, 7)
[6]:
datetime.date(2006, 7, 24)
Or the second business day after the 15th of 2006.
[7]:
cal.getdate('second bizday after 15th day', 2006)
[7]:
datetime.date(2006, 1, 17)