时间计算从未如此简单:passage-of-time-mcp API全方位参考
【免费下载链接】passage-of-time-mcp🤖🕰️ An MCP server that gives language models temporal awareness and time calculation abilities. Teaching AI the significance of the passage of time through collaborative tool development.项目地址: https://gitcode.com/gh_mirrors/pa/passage-of-time-mcp
passage-of-time-mcp是一个为语言模型提供时间感知和时间计算能力的MCP服务器,通过协作工具开发让AI理解时间流逝的意义。本文将全方位介绍passage-of-time-mcp的API功能,帮助开发者快速掌握时间计算的简单方法。
核心功能概览 🕰️
passage-of-time-mcp提供了一系列强大的时间工具,涵盖了从获取当前时间到复杂时间计算的各种需求。这些工具通过直观的API接口,让时间相关的操作变得简单高效。
图1:passage-of-time-mcp工具菜单,展示了所有可用的时间工具
主要工具包括:
- current_datetime:获取当前日期和时间
- time_difference:计算两个时间戳之间的差异
- time_since:计算自给定时间戳以来经过的时间
- parse_timestamp:解析并转换时间戳为多种格式
- add_time:在时间戳上添加或减去持续时间
- timestamp_context:获取时间戳的上下文信息
- format_duration:将秒数格式化为可读文本
快速开始指南 🚀
要开始使用passage-of-time-mcp,首先需要克隆仓库:
git clone https://gitcode.com/gh_mirrors/pa/passage-of-time-mcp项目的核心代码位于passage_of_time_mcp.py文件中,包含了所有时间工具的实现。
API详细解析 🔍
current_datetime:获取当前时间
current_datetime工具用于获取当前日期和时间,支持指定时区。默认时区为"America/New_York",但可以通过参数指定其他时区。
使用示例:
current_datetime(timezone="UTC")返回结果:
"2024-07-25 12:30:45 UTC"time_difference:计算时间差
time_difference工具可以计算两个时间戳之间的差异,并以多种单位返回结果。时间戳必须采用"YYYY-MM-DD HH:MM:SS"或"YYYY-MM-DD"格式。
图2:time_difference工具详情,展示了参数和功能说明
使用示例:
time_difference( timestamp1="2024-01-15 14:30:00", timestamp2="2024-01-16 15:45:00", unit="auto", timezone="America/New_York" )返回结果:
{ "seconds": 87300, "formatted": "1 day, 1 hour, 15 minutes", "is_negative": false }time_since:计算经过时间
time_since工具计算从给定时间戳到现在经过的时间,并提供人类可读的格式和上下文描述。
使用示例:
time_since(timestamp="2024-07-20 09:15:00", timezone="UTC")返回结果:
{ "seconds": 453600, "formatted": "5 days, 4 hours ago", "context": "this week" }parse_timestamp:解析时间戳
parse_timestamp工具将标准格式的时间戳解析并转换为多种格式,包括ISO 8601、Unix时间戳和人类友好格式。
使用示例:
parse_timestamp( timestamp="2024-07-25 12:30:00", source_timezone="UTC", target_timezone="Asia/Shanghai" )返回结果:
{ "iso": "2024-07-25T20:30:00+08:00", "unix": "1721915400", "human": "July 25, 2024 at 08:30 PM CST", "timezone": "Asia/Shanghai", "day_of_week": "Thursday", "date": "2024-07-25", "time": "20:30:00" }add_time:添加时间
add_time工具允许在给定时间戳上添加或减去指定的持续时间,支持秒、分钟、小时、天和周等单位。
使用示例:
add_time( timestamp="2024-07-25", duration=3, unit="days", timezone="UTC" )返回结果:
{ "result": "2024-07-28", "iso": "2024-07-28T00:00:00+00:00", "description": "next Sunday" }timestamp_context:时间戳上下文
timestamp_context工具提供给定时间戳的上下文信息,包括一天中的时间、星期几、是否为周末、是否为工作时间等。
使用示例:
timestamp_context(timestamp="2024-07-25 14:30:00", timezone="Europe/London")返回结果:
{ "time_of_day": "afternoon", "day_of_week": "Thursday", "is_weekend": false, "is_business_hours": true, "hour_24": 14, "typical_activity": "work_time", "relative_day": "today" }format_duration:格式化持续时间
format_duration工具将秒数格式化为人类可读的文本,支持三种不同的风格:完整、紧凑和极简。
使用示例:
format_duration(seconds=3661, style="full")返回结果:
"1 hour, 1 minute, 1 second"集成指南 🔄
passage-of-time-mcp可以轻松集成到各种应用中。在集成页面中,你可以看到它与其他服务的连接状态。
图3:passage-of-time-mcp集成页面,显示与其他服务的连接状态
要更新集成设置,只需编辑名称和URL,然后点击"Update"按钮。
图4:编辑passage-of-time-mcp集成设置
总结
passage-of-time-mcp提供了一套全面的时间计算API,使复杂的时间操作变得简单直观。无论是获取当前时间、计算时间差,还是解析时间戳,这些工具都能满足你的需求。通过passage_of_time_mcp.py中提供的功能,开发者可以轻松地为应用添加强大的时间感知能力。
无论是新手还是有经验的开发者,都能快速上手并充分利用这些工具来处理各种时间相关的任务。开始使用passage-of-time-mcp,体验时间计算从未如此简单的乐趣!
【免费下载链接】passage-of-time-mcp🤖🕰️ An MCP server that gives language models temporal awareness and time calculation abilities. Teaching AI the significance of the passage of time through collaborative tool development.项目地址: https://gitcode.com/gh_mirrors/pa/passage-of-time-mcp
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考