用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/fabioc-aloha/Alex_Skill_Mall --skill date-threshold-arithmetic命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | date-threshold-arithmetic |
| description | Date comparisons at thresholds fail due to fractional days: |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Date comparisons at thresholds fail due to fractional days:
const daysBetween = (Date.now() - someDate.getTime()) / (1000 * 60 * 60 * 24);
// someDate is "exactly 7 days ago"
// daysBetween = 7.000012 (due to milliseconds)
// if (daysBetween > 7) { ... } // TRUE — unexpected!
Always Math.floor() before threshold comparison.
function daysSince(date) {
const ms = Date.now() - new Date(date).getTime();
return Math.floor(ms / (1000 * 60 * 60 * 24));
}
// Now "exactly 7 days" = 7, not 7.000012
if (daysSince(lastCheck) > 7) {
// Truly more than 7 full days
}
| Code | Bug |
|---|---|
days > 7 | Triggers on 7.0001 |
days >= 7 | Doesn't trigger on 6.9999 |
days === 7 | Never true for fractional values |
// Days since (full days only)
const fullDays = Math.floor((now - then) / MS_PER_DAY);
// Is it past the threshold?
if (fullDays > threshold) { ... }
// Is it on or past the threshold?
if (fullDays >= threshold) { ... }
// Is it exactly N days?
if (fullDays === threshold) { ... }
// "Run if last run was more than 24 hours ago"
const lastRun = new Date(stored.lastRunTime);
const hoursSince = (Date.now() - lastRun.getTime()) / (1000 * 60 * 60);
// Use Math.floor for "full hours"
if (Math.floor(hoursSince) >= 24) {
runTask();
}
// Test edge case
const exactlySevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
console.log(daysSince(exactlySevenDaysAgo)); // Should be 7, not 7.xxx
quality dates javascript bugs