Created
October 21, 2022 18:24
-
-
Save pablocastelo/4460410500eecd498bbfdc0c153cc150 to your computer and use it in GitHub Desktop.
Make a list of Quincenas (pay-check day) in Mexico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import holidays | |
def get_quincenas(start_date, end_date): | |
mx_holidays = holidays.country_holidays('MX') | |
date_range = pd.date_range(start_date, end_date, freq='D') | |
quincenas = [] | |
for d in date_range: | |
if d.day == 15 or d.is_month_end: | |
day_shift = 0 | |
while (d + timedelta(days=day_shift)).day_of_week in [5, 6] or mx_holidays.get(d + timedelta(days=day_shift)) is not None: | |
day_shift -= 1 | |
r = d + timedelta(days=day_shift) | |
quincenas.append(r.date()) | |
return quincenas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment