月经周期计算器
预测下次月经日、排卵日和受孕窗口期。
月经周期计算器根据上次月经开始日期和平均周期长度,预测下次月经日期、排卵日及排卵前后的受孕窗口期。大多数月经周期为 21 至 35 天,常见平均值为 28 天,但每个人的周期都是独特的。
使用方法:输入上次月经开始日期和平均周期天数,工具会立即计算下次月经预期日期、预计排卵日(28 天周期约为第 14 天)以及最易受孕的日期范围。还可同时查看未来多个周期的预测。
本工具提供的是参考估算,实际周期可能因压力、疾病、运动或激素变化而有所不同。如需做出与生育或避孕相关的医学决策,请务必咨询医疗专业人员。
常见问题
代码实现
from datetime import date, timedelta
def menstrual_cycle(last_period: date, cycle_length: int = 28, period_length: int = 5) -> dict:
"""
Predict next period and fertile window based on cycle data.
Ovulation assumed at cycle_length - 14 days (luteal phase = 14 days).
"""
ovulation_day = cycle_length - 14
next_period = last_period + timedelta(days=cycle_length)
ovulation_date = last_period + timedelta(days=ovulation_day)
fertile_start = ovulation_date - timedelta(days=5)
fertile_end = ovulation_date
return {
"last_period": last_period.strftime("%Y-%m-%d"),
"next_period": next_period.strftime("%Y-%m-%d"),
"ovulation_date": ovulation_date.strftime("%Y-%m-%d"),
"fertile_window": f"{fertile_start.strftime('%Y-%m-%d')} to {fertile_end.strftime('%Y-%m-%d')}",
"period_ends": (last_period + timedelta(days=period_length - 1)).strftime("%Y-%m-%d"),
}
result = menstrual_cycle(date(2025, 3, 1), cycle_length=28, period_length=5)
print(f"Last Period : {result['last_period']}")
print(f"Period Ends : {result['period_ends']}")
print(f"Fertile Window : {result['fertile_window']}")
print(f"Ovulation : {result['ovulation_date']}")
print(f"Next Period : {result['next_period']}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.