Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| from hijridate import Hijri, Gregorian | |
| from datetime import date | |
| # Add a sidebar with radio buttons | |
| st.sidebar.title("Navigation") | |
| option = st.sidebar.radio( | |
| "Choose an option", | |
| ( | |
| "Three Month Deadline Converter", | |
| "60 Days Deadline Converter", | |
| "90 Days Deadline Converter", | |
| "Convert Hijri Date to Gregorian Date", | |
| "Add 20 Years to Filing Date", | |
| "Add 15 Years to Filing Date", | |
| "Add 10 Years to Filing Date", | |
| ), | |
| ) | |
| # Function to add days to a Hijri date | |
| def add_hijri_days(hijri_date, days): | |
| day = hijri_date.day | |
| month = hijri_date.month | |
| year = hijri_date.year | |
| while days > 0: | |
| days_in_current_month = Hijri(year, month, 1).month_length() | |
| remaining_days_in_month = days_in_current_month - day + 1 # Include current day | |
| if days >= remaining_days_in_month: | |
| days -= remaining_days_in_month | |
| day = 1 | |
| if month == 12: | |
| month = 1 | |
| year += 1 | |
| else: | |
| month += 1 | |
| else: | |
| day += days | |
| days = 0 | |
| new_hijri_date = Hijri(year, month, day) | |
| return new_hijri_date | |
| # Function to add months to a Hijri date | |
| def add_hijri_months(hijri_date, months): | |
| month = hijri_date.month | |
| year = hijri_date.year | |
| day = hijri_date.day | |
| total_months = (year - 1) * 12 + (month - 1) + months | |
| new_year = total_months // 12 + 1 | |
| new_month = total_months % 12 + 1 | |
| max_day = Hijri(new_year, new_month, 1).month_length() | |
| if day > max_day: | |
| day = max_day | |
| new_hijri_date = Hijri(new_year, new_month, day) | |
| return new_hijri_date | |
| # Function to add years to a Hijri date | |
| def add_hijri_years(hijri_date, years): | |
| year = hijri_date.year + years | |
| month = hijri_date.month | |
| day = hijri_date.day | |
| max_day = Hijri(year, month, 1).month_length() | |
| if day > max_day: | |
| day = max_day | |
| new_hijri_date = Hijri(year, month, day) | |
| return new_hijri_date | |
| # Function to calculate three-month deadlines | |
| def three_month_deadlines(): | |
| st.title("Three Month Deadline Converter") | |
| start_date = st.date_input("Select a Gregorian start date") | |
| date_data = [] | |
| if start_date: | |
| # Convert start_date to Hijri | |
| try: | |
| gregorian_date = Gregorian(start_date.year, start_date.month, start_date.day) | |
| hijri_start_date = gregorian_date.to_hijri() | |
| except OverflowError as e: | |
| st.error(f"Error converting Gregorian to Hijri date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Gregorian date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Chosen Start Date", | |
| "Hijri Date": hijri_start_date.isoformat(), | |
| "Gregorian Date": gregorian_date.isoformat(), | |
| } | |
| ) | |
| # Add 3 Hijri months to Hijri date | |
| deadline_hijri = add_hijri_months(hijri_start_date, 3) | |
| # Convert deadline back to Gregorian | |
| try: | |
| deadline_gregorian = deadline_hijri.to_gregorian() | |
| except OverflowError as e: | |
| st.error(f"Error converting Hijri to Gregorian date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Hijri date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Deadline - Three Hijri months from start date", | |
| "Hijri Date": deadline_hijri.isoformat(), | |
| "Gregorian Date": deadline_gregorian.isoformat(), | |
| } | |
| ) | |
| # Function to add months and store results | |
| def add_months_and_store_from_deadline(deadline_hijri, months): | |
| for i in range(1, months + 1): | |
| future_hijri = add_hijri_months(deadline_hijri, i) | |
| try: | |
| future_gregorian = future_hijri.to_gregorian() | |
| except OverflowError as e: | |
| st.error(f"Error converting Hijri to Gregorian date: {e}") | |
| continue | |
| except ValueError as e: | |
| st.error(f"Invalid Hijri date: {e}") | |
| continue | |
| description = f"{i} Hijri month extension from deadline" | |
| date_data.append( | |
| { | |
| "Description": description, | |
| "Hijri Date": future_hijri.isoformat(), | |
| "Gregorian Date": future_gregorian.isoformat(), | |
| } | |
| ) | |
| add_months_and_store_from_deadline(deadline_hijri, 3) | |
| df = pd.DataFrame(date_data) | |
| st.write("### Date Conversion Table") | |
| st.dataframe(df) | |
| # Function to calculate 60 days deadlines | |
| def sixty_days_deadlines(): | |
| st.title("60 Days Deadline Converter") | |
| start_date = st.date_input("Select a Gregorian start date") | |
| date_data = [] | |
| if start_date: | |
| # Convert start date to Hijri date | |
| try: | |
| gregorian_date = Gregorian(start_date.year, start_date.month, start_date.day) | |
| hijri_date = gregorian_date.to_hijri() | |
| except OverflowError as e: | |
| st.error(f"Error converting Gregorian to Hijri date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Gregorian date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Chosen Start Date", | |
| "Hijri Date": hijri_date.isoformat(), | |
| "Gregorian Date": gregorian_date.isoformat(), | |
| } | |
| ) | |
| # Add 60 Hijri days to Hijri date | |
| deadline_hijri_date = add_hijri_days(hijri_date, 60) | |
| # Convert deadline Hijri date to Gregorian date | |
| try: | |
| deadline_gregorian_date = deadline_hijri_date.to_gregorian() | |
| except OverflowError as e: | |
| st.error(f"Error converting Hijri to Gregorian date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Hijri date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Deadline - 60 Hijri days from start date", | |
| "Hijri Date": deadline_hijri_date.isoformat(), | |
| "Gregorian Date": deadline_gregorian_date.isoformat(), | |
| } | |
| ) | |
| df = pd.DataFrame(date_data) | |
| st.write("### Date Conversion Table") | |
| st.dataframe(df) | |
| # Function to calculate 90 days deadlines | |
| def ninety_days_deadlines(): | |
| st.title("90 Days Deadline Converter") | |
| start_date = st.date_input("Select a Gregorian start date") | |
| date_data = [] | |
| if start_date: | |
| # Convert start date to Hijri date | |
| try: | |
| gregorian_date = Gregorian(start_date.year, start_date.month, start_date.day) | |
| hijri_date = gregorian_date.to_hijri() | |
| except OverflowError as e: | |
| st.error(f"Error converting Gregorian to Hijri date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Gregorian date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Chosen Start Date", | |
| "Hijri Date": hijri_date.isoformat(), | |
| "Gregorian Date": gregorian_date.isoformat(), | |
| } | |
| ) | |
| # Add 90 Hijri days to Hijri date | |
| deadline_hijri_date = add_hijri_days(hijri_date, 90) | |
| # Convert deadline Hijri date to Gregorian date | |
| try: | |
| deadline_gregorian_date = deadline_hijri_date.to_gregorian() | |
| except OverflowError as e: | |
| st.error(f"Error converting Hijri to Gregorian date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Hijri date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Deadline - 90 Hijri days from start date", | |
| "Hijri Date": deadline_hijri_date.isoformat(), | |
| "Gregorian Date": deadline_gregorian_date.isoformat(), | |
| } | |
| ) | |
| df = pd.DataFrame(date_data) | |
| st.write("### Date Conversion Table") | |
| st.dataframe(df) | |
| # Function to convert Hijri date to Gregorian date | |
| def convert_hijri_to_gregorian(): | |
| st.title("Convert Hijri Date to Gregorian Date") | |
| # Inputs for Hijri year, month, and day | |
| hijri_year = st.number_input("Enter Hijri Year:", min_value=1, step=1, value=1445) | |
| hijri_month = st.number_input("Enter Hijri Month:", min_value=1, max_value=12, step=1, value=1) | |
| hijri_day = st.number_input("Enter Hijri Day:", min_value=1, max_value=30, step=1, value=1) | |
| if st.button("Convert"): | |
| try: | |
| # Create Hijri date | |
| hijri_date = Hijri(int(hijri_year), int(hijri_month), int(hijri_day)) | |
| # Convert Hijri date to Gregorian date | |
| gregorian_date = hijri_date.to_gregorian() | |
| st.write(f"The Gregorian date is: {gregorian_date.isoformat()}") | |
| except OverflowError as e: | |
| st.error(f"Date out of supported range: {e}") | |
| except ValueError as e: | |
| st.error(f"Invalid Hijri date: {e}") | |
| # Function to add years to filing date according to Hijri calendar | |
| def add_years_to_filing_date(years): | |
| st.title(f"Add {years} Hijri Years to Filing Date") | |
| filing_date = st.date_input("Select a Gregorian filing date") | |
| date_data = [] | |
| if filing_date: | |
| # Convert filing date to Hijri date | |
| try: | |
| gregorian_date = Gregorian(filing_date.year, filing_date.month, filing_date.day) | |
| hijri_date = gregorian_date.to_hijri() | |
| except OverflowError as e: | |
| st.error(f"Error converting Gregorian to Hijri date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Gregorian date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": "Filing Date", | |
| "Hijri Date": hijri_date.isoformat(), | |
| "Gregorian Date": gregorian_date.isoformat(), | |
| } | |
| ) | |
| # Add years to Hijri date | |
| future_hijri_date = add_hijri_years(hijri_date, years) | |
| # Convert future Hijri date to Gregorian date | |
| try: | |
| future_gregorian_date = future_hijri_date.to_gregorian() | |
| except OverflowError as e: | |
| st.error(f"Error converting Hijri to Gregorian date: {e}") | |
| return | |
| except ValueError as e: | |
| st.error(f"Invalid Hijri date: {e}") | |
| return | |
| date_data.append( | |
| { | |
| "Description": f"Date after adding {years} Hijri years", | |
| "Hijri Date": future_hijri_date.isoformat(), | |
| "Gregorian Date": future_gregorian_date.isoformat(), | |
| } | |
| ) | |
| df = pd.DataFrame(date_data) | |
| st.write(f"### Date Conversion Table ({years} Hijri Years Added)") | |
| st.dataframe(df) | |
| # Function to add years to a Hijri date (used in adding years to filing date) | |
| def add_hijri_years(hijri_date, years): | |
| year = hijri_date.year + years | |
| month = hijri_date.month | |
| day = hijri_date.day | |
| # Adjust day if necessary | |
| max_day = Hijri(year, month, 1).month_length() | |
| if day > max_day: | |
| day = max_day | |
| new_hijri_date = Hijri(year, month, day) | |
| return new_hijri_date | |
| # Sidebar navigation using radio buttons | |
| if option == "Three Month Deadline Converter": | |
| three_month_deadlines() | |
| elif option == "60 Days Deadline Converter": | |
| sixty_days_deadlines() | |
| elif option == "90 Days Deadline Converter": | |
| ninety_days_deadlines() | |
| elif option == "Convert Hijri Date to Gregorian Date": | |
| convert_hijri_to_gregorian() | |
| elif option == "Add 20 Years to Filing Date": | |
| add_years_to_filing_date(20) | |
| elif option == "Add 15 Years to Filing Date": | |
| add_years_to_filing_date(15) | |
| elif option == "Add 10 Years to Filing Date": | |
| add_years_to_filing_date(10) | |