Калькулятор интервального голодания

Планируйте интервальное голодание по методам 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.