relative_time
Calculate the relative time from a specified date and time using the format YYYY-MM-DD HH:mm:ss. Enhance time awareness in applications with precise relative time calculations.
Instructions
Get the relative time from now.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time | Yes | The time to get the relative time from now. Format: YYYY-MM-DD HH:mm:ss |
Implementation Reference
- src/index.ts:171-173 (handler)The core handler function that executes the 'relative_time' tool logic, computing the relative time from now using dayjs.fromNow().function getRelativeTime(time: string) { return dayjs(time).fromNow(); }
- src/tools.ts:35-48 (schema)The Tool definition including name, description, and inputSchema for the 'relative_time' tool.export const RELATIVE_TIME: Tool = { name: 'relative_time', description: 'Get the relative time from now.', inputSchema: { type: 'object', properties: { time: { type: 'string', description: 'The time to get the relative time from now. Format: YYYY-MM-DD HH:mm:ss', }, }, required: ['time'], }, };
- src/index.ts:32-33 (registration)Registration of the RELATIVE_TIME tool in the list returned by ListToolsRequestHandler.tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], };
- src/index.ts:57-73 (handler)The dispatch case in CallToolRequestHandler that validates args and calls the getRelativeTime handler.case 'relative_time': { if (!checkRelativeTimeArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const time = args.time; const result = getRelativeTime(time); return { success: true, content: [ { type: 'text', text: result, }, ], }; }
- src/index.ts:213-220 (helper)Helper function for input validation/schema checking for relative_time args.function checkRelativeTimeArgs(args: unknown): args is { time: string } { return ( typeof args === 'object' && args !== null && 'time' in args && typeof args.time === 'string' ); }