Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel
time-subtraction.md1.03 kB
# Time Subtraction with date-fns (Verified 2025-07-18) **Key Findings**: 1. **Subtraction Functions**: - Individual functions: `subYears()`, `subMonths()`, `subDays()`, `subHours()`, `subMinutes()`, `subSeconds()` - **Important**: `subX(date, n)` is exactly equivalent to `addX(date, -n)` - All functions are immutable - return new Date objects - Negative values in subtraction functions add time (double negative) 2. **Equivalence with Addition**: ```typescript subDays(date, 5) === addDays(date, -5) // true subMonths(date, 2) === addMonths(date, -2) // true // This holds for all units ``` 3. **Month-end Handling**: - March 31 - 1 month = Feb 28 (or 29 in leap year) - Same intelligent boundary handling as addition 4. **DST Behavior**: - Subtraction across DST boundaries adjusts hours - March 15 - 2 months can result in 11:30 instead of 10:30 5. **Implementation Strategy**: - Can reuse `addTime` implementation with negated amounts - No need for separate subtraction logic

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/pshempel/mcp-time-server-node'

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