"""OPT and STEM OPT Form I-765 filing-window estimator. MIT License. No dependencies. Rules: Post-completion OPT (c)(3)(B): up to 90 days before the program end date, no later than 60 days after it, and within 30 days of the DSO recommendation (Form I-765 instructions, edition 08/21/25; USCIS Form I-765 page). STEM OPT (c)(3)(C): up to 90 days before the current OPT EAD expires and within 60 days of the DSO's STEM recommendation (8 CFR 214.2(f)(11)(i)(C); I-765 instructions). SEVP says USCIS must receive it no later than the current post-completion OPT end date (SEVIS Help Hub, F-1 STEM OPT page). USCIS records the receipt date as the actual date of receipt at the filing location (8 CFR 103.2(a)(7)(i)), not the date you mail it. Usage: python3 filing_window.py opt PROGRAM_END DSO_RECOMMENDATION [RECEIPT_DATE] python3 filing_window.py stem OPT_EAD_END DSO_STEM_RECOMMENDATION [RECEIPT_DATE] Dates are YYYY-MM-DD. """ import sys from datetime import date, timedelta DISCLAIMER = ("Estimate from the dates you entered. Day-boundary counting is not " "defined by USCIS; file inside the window with margin. Not legal advice.") def _window(opens, closes, recommendation, valid_days): earliest = max(opens, recommendation) latest = min(closes, recommendation + timedelta(days=valid_days)) return (earliest, latest) if earliest <= latest else None def opt_window(program_end, dso_recommendation): """(earliest, latest) receipt dates for a post-completion OPT I-765, or None.""" return _window(program_end - timedelta(days=90), program_end + timedelta(days=60), dso_recommendation, 30) def stem_window(opt_ead_end, dso_stem_recommendation): """(earliest, latest) receipt dates for a STEM OPT I-765, or None. latest is capped at opt_ead_end: the filing must be received while the EAD is unexpired. """ return _window(opt_ead_end - timedelta(days=90), opt_ead_end, dso_stem_recommendation, 60) def is_timely(window, receipt_date): """True if USCIS's receipt date falls inside the window (both ends inclusive).""" return window is not None and window[0] <= receipt_date <= window[1] def empty_reason(kind, end_date, recommendation): """Why opt_window/stem_window returned None (kind is 'opt' or 'stem'), else None.""" valid_days, closes = (30, end_date + timedelta(days=60)) if kind == "opt" else (60, end_date) if recommendation + timedelta(days=valid_days) < end_date - timedelta(days=90): return ("DSO recommendation is too old; it expires before the filing window " "opens. Ask your DSO for a new recommendation.") if recommendation > closes: if kind == "opt": return ("DSO recommendation is more than 60 days after the program end date, " "so the OPT filing deadline has passed. Talk to your DSO.") return ("DSO recommendation is after your OPT EAD end date; a STEM I-765 must be " "filed before the EAD expires. Talk to your DSO.") return None def main(argv): if len(argv) not in (3, 4) or argv[0] not in ("opt", "stem"): sys.exit(__doc__) try: kind = argv[0] end_date, rec = date.fromisoformat(argv[1]), date.fromisoformat(argv[2]) receipt = date.fromisoformat(argv[3]) if len(argv) == 4 else None except ValueError as e: sys.exit(f"Bad date ({e}). Use YYYY-MM-DD.") window = opt_window(end_date, rec) if kind == "opt" else stem_window(end_date, rec) if window is None: print("No filing window:", empty_reason(kind, end_date, rec)) else: print(f"File so USCIS receives it between {window[0]} and {window[1]} (inclusive).") if receipt is not None: print(f"Receipt date {receipt}:", "inside the window" if is_timely(window, receipt) else "OUTSIDE the window") print(DISCLAIMER) if __name__ == "__main__": main(sys.argv[1:])