File size: 2,092 Bytes
f9d6ed6
39dce55
b6d8da7
f9d6ed6
 
b6d8da7
f9d6ed6
b6d8da7
f9d6ed6
 
 
c5b0f62
39dce55
b6d8da7
39dce55
 
b6d8da7
 
 
39dce55
 
b6d8da7
 
 
 
39dce55
b6d8da7
 
 
 
 
 
 
 
 
39dce55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
from datetime import datetime
from dateutil.relativedelta import relativedelta

# App Title and Description
st.title("πŸŽ‚ Advanced Age Calculator")
st.write("""
Calculate your age in years, months, and days!  
See your next 5 birthdays and get a detailed textual output in English.  
""")

# Input Section with a minimum date of January 1, 1950
dob = st.date_input("Select Your Date of Birth (YYYY-MM-DD):", min_value=datetime(1950, 1, 1))

# Button to trigger calculation
if st.button("Calculate Age and Next Birthdays"):
    if dob:
        today = datetime.now()
        dob_datetime = datetime.combine(dob, datetime.min.time())

        # Calculate age in years, months, and days
        age_years = today.year - dob.year - ((today.month, today.day) < (dob.month, dob.day))
        age_months = relativedelta(today, dob_datetime).months
        age_days = (today - dob_datetime).days % 30  # Approximation for days in the current month

        # Calculate next 5 birthdays
        next_birthdays = []
        next_birthday = datetime(today.year, dob.month, dob.day)
        if next_birthday < today:
            next_birthday = datetime(today.year + 1, dob.month, dob.day)

        for _ in range(5):
            next_birthdays.append(next_birthday.strftime("%A, %d %B %Y"))
            next_birthday = next_birthday.replace(year=next_birthday.year + 1)

        # Display Age
        st.subheader("πŸ•’ Your Age:")
        st.write(f"**Years:** {age_years}")
        st.write(f"**Months:** {age_months}")
        st.write(f"**Days:** {age_days}")

        # Display Next 5 Birthdays
        st.subheader("πŸŽ‰ Next 5 Birthdays:")
        for idx, birthday in enumerate(next_birthdays, start=1):
            st.write(f"{idx}. {birthday}")

        # English Textual Output
        st.subheader("πŸ“œ Age in English:")
        st.write(f"You are **{age_years} years, {age_months} months, and {age_days} days old**.")
        st.write("Your next five birthdays will be on the dates listed above.")
    else:
        st.write("Please select a valid date of birth.")