跳到内容
🛠️ToolsShed

睡眠周期计算器

根据 90 分钟睡眠周期计算最佳入睡和起床时间。

关于此工具

睡眠周期计算器基于90分钟的睡眠周期,帮助您优化自然睡眠模式。睡眠周期是人体的自然节奏,依次经历浅睡眠、深睡眠和快速眼动睡眠(梦境睡眠),然后重复循环。在完整周期结束时醒来会让您感到精神焕发,但在周期中途醒来则可能导致您在几小时内感到昏昏欲睡和迷茫。

使用此计算器时,只需输入您期望的入睡或起床时间,它就会计算出相应的最佳时间。例如,如果您需要在早上7点起床,该工具会计算您应该何时入睡以完成完整的90分钟周期——建议时间如晚上10点30分、午夜12点或凌晨1点30分。无论您是计划整夜睡眠还是午睡,这种方法都能帮助您将睡眠与身体的自然节奏保持一致。

常见问题

代码实现

from datetime import datetime, timedelta

SLEEP_CYCLE_MINUTES = 90
FALL_ASLEEP_MINUTES = 14  # Average time to fall asleep

def wake_times_from_bedtime(bedtime: datetime, cycles: int = 5) -> list[datetime]:
    """Given a bedtime, return optimal wake-up times after N full 90-min cycles."""
    fall_asleep = bedtime + timedelta(minutes=FALL_ASLEEP_MINUTES)
    return [
        fall_asleep + timedelta(minutes=SLEEP_CYCLE_MINUTES * i)
        for i in range(1, cycles + 1)
    ]

def bedtimes_from_wake(wake_time: datetime, cycles: int = 5) -> list[datetime]:
    """Given a desired wake time, return bedtimes that allow N full 90-min cycles."""
    return [
        wake_time - timedelta(minutes=SLEEP_CYCLE_MINUTES * i + FALL_ASLEEP_MINUTES)
        for i in range(1, cycles + 1)
    ]

# Example: bedtime at 11 PM
bedtime = datetime.now().replace(hour=23, minute=0, second=0, microsecond=0)
print(f"Bedtime: {bedtime.strftime('%I:%M %p')}")
print("Best wake times:")
for t in wake_times_from_bedtime(bedtime):
    print(f"  {t.strftime('%I:%M %p')} ({(t - bedtime).seconds // 60} min)")

# Example: must wake at 7 AM
wake = datetime.now().replace(hour=7, minute=0, second=0, microsecond=0)
print(f"\nWake time: {wake.strftime('%I:%M %p')}")
print("Best bedtimes:")
for t in bedtimes_from_wake(wake):
    print(f"  {t.strftime('%I:%M %p')}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.