File size: 12,018 Bytes
352d935
0331a04
c76d97c
b462ee9
352d935
a87fcd9
c0d17ca
a87fcd9
c0d17ca
dabc084
 
 
 
 
 
 
 
 
c0d17ca
 
b462ee9
8b31f7c
c76d97c
 
 
 
 
 
6ff091a
c76d97c
6ff091a
 
c76d97c
 
 
 
 
 
 
 
 
 
 
8b31f7c
 
b462ee9
8b31f7c
 
c76d97c
8b31f7c
 
c76d97c
 
8b31f7c
 
c76d97c
 
 
df7334e
c76d97c
8b31f7c
 
b462ee9
8b31f7c
 
 
 
df7334e
c76d97c
 
 
df7334e
c76d97c
8b31f7c
 
c76d97c
0876876
 
 
 
 
 
dabc084
b462ee9
 
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
 
320e15e
8b31f7c
dabc084
 
b462ee9
 
 
 
 
 
 
 
dabc084
 
 
b462ee9
dabc084
 
 
 
0876876
 
dabc084
0876876
8b31f7c
b462ee9
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
 
 
0876876
 
 
 
 
 
 
 
 
 
 
dabc084
b462ee9
 
 
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
b462ee9
8b31f7c
dabc084
 
b462ee9
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
0876876
 
 
 
 
 
 
 
 
 
 
 
dabc084
b462ee9
 
 
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
b462ee9
8b31f7c
dabc084
 
b462ee9
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
0876876
 
 
 
 
 
8b31f7c
0876876
dabc084
0876876
b462ee9
 
 
0876876
 
 
ac55314
 
0876876
 
 
b462ee9
 
0876876
 
c0d17ca
dabc084
b429fda
b462ee9
b429fda
a1d37e2
 
b429fda
dabc084
b462ee9
 
 
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
 
 
8b31f7c
dabc084
 
b462ee9
 
 
 
 
 
 
 
 
dabc084
 
 
 
 
 
 
a1d37e2
 
dabc084
c0d17ca
 
b462ee9
 
 
 
 
 
 
 
 
 
 
 
 
 
a87fcd9
b7c3b77
c0d17ca
da14956
c0d17ca
a1d37e2
 
 
8b31f7c
b429fda
 
 
 
 
b462ee9
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
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)