Time Capsule Calculator

Calculate how long until your time capsule can be opened with countdown and progress tracking.

Quick Set Open Date

よくある質問

コヌド実装

from datetime import date, timedelta
from dateutil.relativedelta import relativedelta

def time_capsule_info(seal_date: date, open_date: date) -> dict:
    """Calculate time capsule duration and milestones."""
    if open_date <= seal_date:
        raise ValueError("Open date must be after seal date")

    delta = relativedelta(open_date, seal_date)
    total_days = (open_date - seal_date).days
    days_remaining = (open_date - date.today()).days

    # Milestone dates
    milestones = {}
    for pct, label in [(25, "25%"), (50, "Halfway"), (75, "75%")]:
        days_offset = int(total_days * pct / 100)
        milestones[label] = seal_date + timedelta(days=days_offset)

    return {
        "seal_date": seal_date.isoformat(),
        "open_date": open_date.isoformat(),
        "duration_years": delta.years,
        "duration_months": delta.months,
        "duration_days": delta.days,
        "total_days": total_days,
        "days_remaining": max(0, days_remaining),
        "milestones": {k: v.isoformat() for k, v in milestones.items()},
        "decade": f"{(open_date.year // 10) * 10}s",
    }

info = time_capsule_info(date(2025, 1, 1), date(2035, 1, 1))
print(f"Duration: {info['duration_years']} years, {info['duration_months']} months")
print(f"Total days: {info['total_days']}")
print(f"Days remaining: {info['days_remaining']}")
print(f"Opening decade: the {info['decade']}")
for label, dt in info["milestones"].items():
    print(f"  {label}: {dt}")

Comments & Feedback

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