🛠️ToolsShed

間欠的断食計算ツール

16:8・18:6・5:2などの断食スケジュールを計画します。

8h
食事時間
食事開始 12:00 PM
16h
断食
断食開始 8:00 PM
12:00 PM
食事開始
8:00 PM
食事終了

ヒント

断食中は水、ブラックコーヒー、またはプレーンティーを飲んでください。

断食を終える際は、バランスの取れた栄養豊富な食事をとりましょう。

継続性が鍵です。毎日同じスケジュールを守るのが最も効果的です。

よくある質問

コード実装

from datetime import datetime, timedelta

def calculate_fasting_window(start_time_str: str, fasting_hours: int) -> dict:
    """
    Calculate fasting and eating windows for intermittent fasting.
    start_time_str: when the fast started, e.g. "2025-03-20 20:00"
    fasting_hours: duration of fast in hours (e.g. 16 for 16:8)
    """
    fmt = "%Y-%m-%d %H:%M"
    fast_start = datetime.strptime(start_time_str, fmt)
    fast_end = fast_start + timedelta(hours=fasting_hours)
    eating_hours = 24 - fasting_hours
    eating_end = fast_end + timedelta(hours=eating_hours)

    now = datetime.now()
    elapsed = (now - fast_start).total_seconds() / 3600
    remaining = max(0, fasting_hours - elapsed)

    return {
        "fast_start": fast_start.strftime(fmt),
        "fast_end": fast_end.strftime(fmt),
        "eating_window_end": eating_end.strftime(fmt),
        "hours_elapsed": round(elapsed, 2),
        "hours_remaining": round(remaining, 2),
        "protocol": f"{fasting_hours}:{eating_hours}",
    }

result = calculate_fasting_window("2025-03-20 20:00", 16)
print(f"Protocol          : {result['protocol']}")
print(f"Fast Start        : {result['fast_start']}")
print(f"Fast End          : {result['fast_end']}")
print(f"Eating Window End : {result['eating_window_end']}")
print(f"Hours Elapsed     : {result['hours_elapsed']}")
print(f"Hours Remaining   : {result['hours_remaining']}")

Comments & Feedback

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