Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,21 +39,23 @@ def has_system_availability(schedule_data, class_selected, day_selected, start_t
|
|
39 |
|
40 |
# Convert string day and time to datetime
|
41 |
def get_class_datetime(day_selected, start_time_selected):
|
42 |
-
days_of_week = ["یکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه"
|
43 |
-
today = JalaliDate.today()
|
44 |
-
current_day_index = today.
|
45 |
|
46 |
-
#
|
47 |
target_day_index = days_of_week.index(day_selected)
|
48 |
-
|
|
|
|
|
49 |
|
50 |
# If the class day is today but time has passed, move to the next week
|
51 |
-
|
|
|
52 |
delta_days = 7
|
53 |
|
54 |
class_date = today + timedelta(days=delta_days)
|
55 |
-
|
56 |
-
class_datetime = datetime.combine(class_date.to_gregorian(), class_time)
|
57 |
|
58 |
return class_datetime
|
59 |
|
|
|
39 |
|
40 |
# Convert string day and time to datetime
|
41 |
def get_class_datetime(day_selected, start_time_selected):
|
42 |
+
days_of_week = ["شنبه", "یکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه"]
|
43 |
+
today = JalaliDate.today().to_gregorian()
|
44 |
+
current_day_index = today.weekday() # This returns the current day of the week as an integer (0=Monday, 6=Sunday)
|
45 |
|
46 |
+
# Adjusting days of the week to start from Saturday to match the Persian calendar
|
47 |
target_day_index = days_of_week.index(day_selected)
|
48 |
+
adjusted_day_index = (target_day_index + 1) % 7 # Mapping Saturday to 0, ..., Friday to 6
|
49 |
+
|
50 |
+
delta_days = (adjusted_day_index - current_day_index) % 7
|
51 |
|
52 |
# If the class day is today but time has passed, move to the next week
|
53 |
+
class_time = datetime.strptime(start_time_selected, "%H:%M").time()
|
54 |
+
if delta_days == 0 and class_time < datetime.now().time():
|
55 |
delta_days = 7
|
56 |
|
57 |
class_date = today + timedelta(days=delta_days)
|
58 |
+
class_datetime = datetime.combine(class_date, class_time)
|
|
|
59 |
|
60 |
return class_datetime
|
61 |
|