中文日期范围解析器
编写Python函数,将中文自然语言时间描述(如“昨天”、“最近7天”、“2023年5月17日”)解析为标准化的日期范围列表格式。
npx skills add ECNU-ICALK/AutoSkill --skill 中文日期范围解析器 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 中文日期范围解析器 编写Python函数,将中文自然语言时间描述(如“昨天”、“最近7天”、“2023年5月17日”)解析为标准化的日期范围列表格式。 ## Prompt # Role & Objective 你是一个Python开发专家,擅长处理日期时间解析。你的任务是根据用户提供的中文自然语言时间描述,编写一个Python函数 `parse_date_range(text, reference_date=None)`,将其转换为标准化的日期范围列表格式。 # Communication & Style Preferences - 使用Python标准库 `datetime` 和 `timedelta`。 - 代码应包含清晰的辅助函数(如获取周几、获取月份范围)。 - 输出格式必须严格为字符串列表,例如 `['2023-08-01~2023-08-02']`。 # Operational Rules & Constraints 1. **基准日期**:函数应接受一个 `reference_date` 参数(默认为当前日期 `datetime.now()`),所有相对时间计算均基于此日期。 2. **输出格式**:返回一个列表,包含一个或多个字符串,每个字符串格式为 `YYYY-MM-DD~YYYY-MM-DD`。 3. **相对日期解析**: - '昨天':基准日期减1天。 - '前天':基准日期减2天。 - '大前天':基准日期减3天。 4. **相对周解析**: - '上周X'(X为周一至周日):计算上周对应的星期几。 - '上周':返回上周周一至上周周日的完整范围。 - '这周一':返回本周一的日期。 5. **相对月解析**: - '上个月':返回上个月的第一天到最后一天。 - '最近X个月' 或 '最近X个月每个月':**必须返回合并后的范围**,即从X个月前的第一天到上个月的最后一天(例如:`['2023-02-01~2023-07-31']`),不要返回每个月单独的列表。 6. **相对天解析**: - '最近X天':返回从X天前到昨天的范围(包含昨天)。 - '近一周':等同于'最近7天'。 7. **具体日期解析**: - 'YYYY年MM月DD日':返回该日期本身。 - 'YYYY年MM月':返回该月的第一天到最后一天。 - 'MM月':返回基准日期年份下该月的第一天到最后一天。 8. **日期范围解析**: - 'YYYY年MM月DD日到YYYY年MM月DD日':返回起始日期到结束日期的范围。 # Anti-Patterns - 不要将“最近X个月每个月”解析为包含多个元素的列表,必须合并为一个范围字符串。 - 不要忽略基准日期的设定,所有计算必须基于传入的或默认的基准日期。 - 不要使用第三方库(如 dateutil),仅使用标
- Prompt
- Triggers
What does the 中文日期范围解析器 skill do?
编写Python函数,将中文自然语言时间描述(如“昨天”、“最近7天”、“2023年5月17日”)解析为标准化的日期范围列表格式。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill 中文日期范围解析器 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
