{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# getdate\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from bizdays import Calendar\n", "cal = Calendar.load(filename='ANBIMA.cal')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The desired date is the 15th day of May 2002.\n", "\n", "The expression is `15th day`, year is 2002 and month is 5." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.date(2002, 5, 15)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cal.getdate('15th day', 2002, 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If the month is omited the reference is the year of 2002." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.date(2002, 1, 15)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cal.getdate('15th day', 2002)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the expression `15th day`:\n", "\n", "- `15th` is the position\n", "- `day` is the desired date that in this case is the current date.\n", "\n", "The expression accepts `first`, `second`, `third`, `1st`, `2nd`, `3rd`, `[n]th`, and `last` as valid positions and \n", "\n", "- `day` for regular days inside time span\n", "- `bizday` for business days inside time span\n", "- weekdays: `sun`, `mon`, `tue`, `wed`, `thu`, `fri`, `sat`\n", "\n", "Here it returns the last day and the last business day of 2006." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[datetime.date(2006, 12, 31), datetime.date(2006, 12, 29)]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cal.getdate(['last day', 'last bizday'], 2006)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first and last Monday of 2006." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[datetime.date(2006, 1, 2), datetime.date(2006, 12, 25)]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cal.getdate(['first mon', 'last mon'], 2006)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Using date postions as a reference\n", "\n", "A day can be used as a reference, for example, the first Monday before the 30th day of July 2006." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.date(2006, 7, 24)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cal.getdate('last mon before 30th day', 2006, 7)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or the second business day after the 15th of 2006." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "datetime.date(2006, 1, 17)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cal.getdate('second bizday after 15th day', 2006)" ] } ], "metadata": { "interpreter": { "hash": "4e6da9785688dca07ac236f8ec5f7e99c2c01a8eecf30ede8ddadf573b26e527" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 2 }