jpl_jd_cal
Convert between Julian Day numbers and calendar dates for astronomical calculations and timekeeping in space missions.
Instructions
Julian Day number to/from calendar date/time converter
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| jd | No | Julian date to convert to calendar date | |
| cd | No | Calendar date to convert to Julian date (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss format) |
Implementation Reference
- src/handlers/jpl/jd_cal.ts:13-60 (handler)The core handler function `jdCalHandler` that executes the `jpl_jd_cal` tool. It validates input, transforms parameters, calls the JPL JD Calendar API, adds result as resource, and returns formatted JSON response.
export async function jdCalHandler(args: Record<string, any>) { try { // Base URL for the JD Calendar API const baseUrl = 'https://ssd-api.jpl.nasa.gov/jd_cal.api'; // Validate parameters if (!args.jd && !args.cd) { return { content: [{ type: "text", text: "Error: Either a Julian date (jd) or calendar date (cd) must be provided." }], isError: true }; } // Transform parameter names from underscore to hyphenated format const transformedParams = transformParamsToHyphenated(args); // Make the API request const response = await axios.get(baseUrl, { params: transformedParams }); const data = response.data; // Add response to resources const resourceUri = `jpl://jd_cal/${args.jd || args.cd}`; addResource(resourceUri, { name: `Julian Date / Calendar Date Conversion: ${args.jd || args.cd}`, mimeType: "application/json", text: JSON.stringify(data, null, 2) }); // Format the response return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error accessing JPL Julian Date Calendar API: ${error.message}` }], isError: true }; } }