Skip to content

Instantly share code, notes, and snippets.

@pablocastelo
Created October 21, 2022 18:24
Show Gist options
  • Save pablocastelo/4460410500eecd498bbfdc0c153cc150 to your computer and use it in GitHub Desktop.
Save pablocastelo/4460410500eecd498bbfdc0c153cc150 to your computer and use it in GitHub Desktop.
Make a list of Quincenas (pay-check day) in Mexico
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