mqscript_datetime_format
Format date and time variables in MQScript automation scripts using custom format strings for precise timestamp manipulation in mobile device control operations.
Instructions
Format date time with specified format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dateTimeVariable | Yes | DateTime variable name | |
| format | No | Target format string | yyyy-MM-dd |
| resultVariable | No | Variable name to store result | formattedDate |
Implementation Reference
- src/tools/plugin-commands.ts:205-217 (handler)The handler function that executes the tool: generates MQScript code `resultVariable = DateTime.Format(dateTimeVariable, format)` and returns a descriptive message.handler: async (args: { dateTimeVariable: string; format?: string; resultVariable?: string }) => { const { dateTimeVariable, format = 'yyyy-MM-dd', resultVariable = 'formattedDate' } = args; const script = `${resultVariable} = DateTime.Format(${dateTimeVariable}, "${format}")`; return { content: [ { type: 'text', text: `Generated MQScript DateTime format command:\n\`\`\`\n${script}\n\`\`\`\n\nThis formats "${dateTimeVariable}" to format "${format}".` } ] }; } },
- src/tools/plugin-commands.ts:183-204 (schema)Tool metadata including name, description, and input schema defining required dateTimeVariable and optional format/resultVariable.name: 'mqscript_datetime_format', description: 'Format date time with specified format', inputSchema: { type: 'object' as const, properties: { dateTimeVariable: { type: 'string', description: 'DateTime variable name' }, format: { type: 'string', description: 'Target format string', default: 'yyyy-MM-dd' }, resultVariable: { type: 'string', description: 'Variable name to store result', default: 'formattedDate' } }, required: ['dateTimeVariable'] },
- src/index.ts:64-72 (registration)Registration for listing tools: returns the schema (name, desc, inputSchema) for all tools in ALL_TOOLS, including mqscript_datetime_format.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: Object.values(ALL_TOOLS).map(tool => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema, })), }; });
- src/index.ts:75-88 (registration)Registration for calling tools: looks up tool by name in ALL_TOOLS and invokes its handler.server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => { const { name, arguments: args } = request.params; const tool = Object.values(ALL_TOOLS).find(t => t.name === name); if (!tool) { throw new Error(`Unknown tool: ${name}`); } try { return await tool.handler(args as any || {}); } catch (error) { throw new Error(`Error executing tool ${name}: ${error instanceof Error ? error.message : String(error)}`); } });
- src/index.ts:32-61 (registration)Central tool registry ALL_TOOLS spreads DateTimeCommands (source of mqscript_datetime_format tool definition).const ALL_TOOLS = { // Basic Commands - 基础命令 ...TouchCommands, ...ControlCommands, ...ColorCommands, ...OtherCommands, // Standard Library - 标准库函数 ...MathFunctions, ...StringFunctions, ...TypeConversionFunctions, ...ArrayFunctions, // UI Commands - 界面命令 ...UIControlCommands, ...UIPropertyCommands, ...FloatingWindowCommands, // Extension Commands - 扩展命令 ...ElementCommands, ...DeviceCommands, ...PhoneCommands, ...SysCommands, // Plugin Commands - 插件命令 ...CJsonCommands, ...DateTimeCommands, ...FileCommands, ...TuringCommands, };