Skip to main content
Glama

calculate_date_offset

Calculate legal deadlines and effective dates by adding or subtracting days, months, or years from a starting date. Essential for legal document compliance and timeline management.

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 handler function 'calculate_previous_date' implements the core logic for the 'calculate_date_offset' tool. It parses the input date, applies the specified day, month, and year offsets using dateutil.relativedelta, formats the result as YYYY-MM-DD, and handles errors by returning the original date.
    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)
    The @app.tool decorator registers the 'calculate_date_offset' tool, specifying its name, 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"} )
  • The function parameters with Annotated types define the input schema for the tool, including descriptions for each parameter.
    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:

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