간헐적 단식 계산기
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.