Skip to content

Feature: Add support for monthly and yearly scheduling intervals #4

Description

@srics96

Feature Request

Add support for months and years as scheduling intervals, enabling:

import schedule

# Run on the 1st of every month
schedule.every().month.at(":00:00").do(monthly_report)

# Run every 3 months
schedule.every(3).months.do(quarterly_task)

# Run once a year
schedule.every().year.do(annual_cleanup)

Current Behavior

The library supports seconds, minutes, hours, days, and weeks as interval units. There is no support for months or years.

Implementation Notes

The fix requires changes to schedule/__init__.py:

  1. Add months and years properties to the Job class (similar to existing days, weeks, etc.)
  2. Add the corresponding unit strings to the valid units
  3. Handle the period calculation in _schedule_next_run() — months/years can't use simple timedelta since month lengths vary. Use dateutil.relativedelta or manual date arithmetic.
  4. Add comprehensive tests in test_schedule.py covering:
    • every().month.do(job) — runs monthly
    • every(3).months.do(job) — runs every 3 months
    • every().year.do(job) — runs yearly
    • Edge cases: Feb 29 (leap year), month-end dates (Jan 31 → Feb 28)
  5. Update the __init__.py docstring to document the new intervals

Important: Do NOT add any external dependencies. Use Python's standard library calendar module for month-length calculations. The dateutil library is NOT a dependency of this project.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    fix-meGhost Ship will auto-fix this issue

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions