import holidays from datetime import datetime, timedelta # Get current date/time tday = datetime.now() testday = datetime(2023,12,1,13,13,0) # for debug only tday = testday # for debug only aims_rec_date = tday.strftime('%Y-%m-%d') aims_time = tday.strftime('%H:%M:%S') same_day_despatch_cut_off_time = datetime.strptime(aims_rec_date + " 13:00:00", "%Y-%m-%d %H:%M:%S") add_days = 0 print(f"*******************************\nReceipt: {aims_rec_date} @ {aims_time}") # Early enough for same-day despatch? wk_day = int(tday.strftime('%w')) if wk_day in range(1,5+1): despatch_today = tday < same_day_despatch_cut_off_time print(f"Despatch today: {despatch_today}") if not despatch_today: add_days = 1 else: print("Weekend...") # Set provisional despatch date aims_despatch_date = (tday + timedelta(days=add_days)) # Only interested in these public holidays occasions = [ "New Year's Day", "Good Friday", "Easter Monday [England/Wales/Northern Ireland]", "May Day", "Spring Bank Holiday", "Late Summer Bank Holiday [England/Wales/Northern Ireland]", "Christmas Day", "Boxing Day", ] uk_holidays = holidays.UnitedKingdom() print(f"UK Holiday: {aims_despatch_date in uk_holidays}") # Amend provisional despatch date if not working day while aims_despatch_date in uk_holidays or int(aims_despatch_date.strftime('%w')) in [0,6]: print("****skip-a-day****") try: # amend for public holiday occasion = uk_holidays[aims_despatch_date] if occasion in occasions: aims_despatch_date = (aims_despatch_date + timedelta(days=1)) wk_day = aims_despatch_date.strftime('%w') else: break except Exception as e: # amend for weekend aims_despatch_date = (aims_despatch_date + timedelta(days=1)) wk_day = aims_despatch_date.strftime('%w') print(f"Despatch: {aims_despatch_date.strftime('%Y-%m-%d')}\n*******************************\n")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter