Skip to main content
Glama

calculate_date_offset

Calculate past or future dates by adding/subtracting days, months, or years. Essential for determining legal document effective dates and deadlines in legal research.

Instructions

Calculate dates in the past or future by adding/subtracting time periods. Essential for legal document effective dates and deadlines.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actual_dateYesStarting date in YYYY-MM-DD format
daysNoNumber of days to subtract (use negative for future dates)
monthsNoNumber of months to subtract (use negative for future dates)
yearsNoNumber of years to subtract (use negative for future dates)

Implementation Reference

  • app.py:116-160 (handler)
    The core handler function implementing the calculate_date_offset tool logic. It parses the input date, applies the specified offsets using relativedelta for accurate calendar-aware calculations (handling month/year boundaries), formats the result as YYYY-MM-DD, and includes logging and error handling.
    def calculate_previous_date( actual_date: Annotated[str, "Starting date in YYYY-MM-DD format"], days: Annotated[int, "Number of days to subtract (use negative for future dates)"] = 0, months: Annotated[int, "Number of months to subtract (use negative for future dates)"] = 0, years: Annotated[int, "Number of years to subtract (use negative for future dates)"] = 0 ) -> str: """Calculates a date by adding or subtracting specified time periods from a given date. Essential for legal analysis of effective dates, deadlines, and document validity periods. This function uses dateutil's relativedelta for accurate calendar calculations, handling month/year boundaries correctly. Args: actual_date: Starting date in YYYY-MM-DD format. days: Number of days to add/subtract (negative = future, positive = past). months: Number of months to add/subtract (negative = future, positive = past). years: Number of years to add/subtract (negative = future, positive = past). Returns: str: Calculated date in YYYY-MM-DD format, or original date if calculation fails. Examples: User asks: "What was the date 30 days ago from 2025-01-01?": Parameters: actual_date='2025-01-01', days=30 User asks: "Calculate date 6 months before 2024-07-15": Parameters: actual_date='2024-07-15', months=6 User asks: "What date will it be 2 years from today?": Parameters: actual_date='2025-01-17', years=-2 User asks: "Go back 1 year and 3 months from 2023-12-31": Parameters: actual_date='2023-12-31', months=3, years=1 User asks: "What was the date exactly 90 days before 2024-04-01?": Parameters: actual_date='2024-04-01', days=90 User asks: "Calculate effective date - subtract 14 days from 2025-03-01": Parameters: actual_date='2025-03-01', days=14 User asks: "What date was it 1 year, 2 months, and 5 days ago from 2024-12-25?": Parameters: actual_date='2024-12-25', days=5, months=2, years=1 """ logger.debug(f"calculate_previous_date called with: actual_date={actual_date}, days={days}, months={months}, years={years}") try: result = (datetime.strptime(actual_date, "%Y-%m-%d") - relativedelta(days=days, months=months, years=years)).strftime("%Y-%m-%d") logger.info(f"calculate_previous_date calculated: {actual_date} -> {result} (days={days}, months={months}, years={years})") return result except Exception as e: logger.error(f"Error: {e}") return actual_date
  • app.py:111-115 (registration)
    FastMCP tool registration decorator that binds the calculate_previous_date function to the 'calculate_date_offset' tool name, with description and tags.
    @app.tool( name="calculate_date_offset", description="Calculate dates in the past or future by adding/subtracting time periods. Essential for legal document effective dates and deadlines.", tags={"dates", "calculation", "legal-analysis"} )
  • Input schema defined via Annotated type hints with descriptions, supporting date string and optional day/month/year offsets (positive for past, negative for future). Return type str (YYYY-MM-DD).
    def calculate_previous_date( actual_date: Annotated[str, "Starting date in YYYY-MM-DD format"], days: Annotated[int, "Number of days to subtract (use negative for future dates)"] = 0, months: Annotated[int, "Number of months to subtract (use negative for future dates)"] = 0, years: Annotated[int, "Number of years to subtract (use negative for future dates)"] = 0 ) -> str:
  • app.py:30-30 (helper)
    Import of relativedelta utility used by the handler for precise date arithmetic.
    from dateutil.relativedelta import relativedelta

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/numikel/law-scrapper-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server