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)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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:
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the tool's purpose and context, it doesn't describe important behavioral aspects like whether it performs date validation, how it handles edge cases (e.g., invalid dates, leap years), what format the output takes, or any error conditions. The description is functional but lacks operational transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place: the first states the core functionality, the second provides valuable context about typical use cases. There's zero wasted language, and the most important information (what the tool does) comes first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (date calculations with multiple offset parameters), the presence of a complete input schema (100% coverage) and an output schema (confirmed in context signals), the description provides adequate context. It covers the purpose and typical use cases, though additional behavioral details would be helpful since no annotations exist to supplement understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'adding/subtracting time periods' which aligns with the parameters (days, months, years), but adds no specific semantic information beyond what's already fully documented in the schema (100% coverage). The schema descriptions clearly explain each parameter's purpose, format, and sign conventions, so the description provides minimal additional value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('calculate dates', 'adding/subtracting time periods') and distinguishes it from all sibling tools, which are primarily retrieval operations (get_*, search_*). It explicitly mentions the resource being manipulated (dates) and the operation (calculation with offsets).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool ('Essential for legal document effective dates and deadlines'), which implicitly distinguishes it from sibling tools focused on legal data retrieval. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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