This Python script calculates the number of working days (business days) in each month of the current year for Turkey. It is precisely tailored to take the official holidays in Turkey into account and excludes weekends (Saturdays and Sundays) from the count. The script uses the workalendar
library to retrieve the list of holidays for the specified year.
Before running the script, make sure you have poetry
installed. You can install it using pip:
pip install poetry
-
Import the required libraries with
poetry install --no-root
and define thecount_working_days
function, which calculates the working days between two dates, excluding holidays and weekends. -
Retrieve today's date and the current year.
-
Initialize the Turkey calendar using
workalendar
. -
Get the list of official holidays for the current year and format them as strings in the 'YYYY-MM-DD' format.
-
Iterate through each month of the year, calculating the number of working days for that month using the
count_working_days
function. Adjustments are made for January to account for the fact that the 2nd of January is not observed as a holiday in Turkey. -
Run the code with
poetry run python3 src/working_days_project/working_days_tr.py
. Print the number of working days for each month and the total number of working days for the current year.
The script will output the number of working days for each month and the total working days for the current year. This information can be useful for various business and scheduling purposes.
-
This script assumes that weekends are Saturdays and Sundays. You can modify the
count_working_days
function to consider different weekend days if needed. -
Ensure that the official holidays in Turkey are correctly defined in the
workalendar
library for accurate results. -
The script is tailored for the year in which it is executed. If you want to calculate working days for a different year, simply update the
ThisYear
variable with the desired year.
Feel free to adapt and customize this script for your specific needs or integrate it into other projects where you need to calculate working days.