Skip to content

Commit a7ae2ee

Browse files
adamspdderonnax
authored andcommitted
Convert time object at the very end
1 parent 035c257 commit a7ae2ee

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

appointment/services.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,7 @@ def get_available_slots_for_staff(date, staff_member):
434434
slots = exclude_pending_reschedules(slots, staff_member, date)
435435
appointments = get_appointments_for_date_and_time(date, working_hours_dict['start_time'],
436436
working_hours_dict['end_time'], staff_member)
437-
slots = exclude_booked_slots(appointments, slots, slot_duration)
438-
439-
return [slot.strftime('%I:%M %p') for slot in slots]
437+
return exclude_booked_slots(appointments, slots, slot_duration)
440438

441439

442440
def get_finish_button_text(service) -> str:

appointment/static/js/appointments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let isRequestInProgress = false;
1010
const calendar = new FullCalendar.Calendar(calendarEl, {
1111
initialView: 'dayGridMonth',
1212
initialDate: selectedDate,
13+
timeZone: timezone,
1314
headerToolbar: {
1415
left: 'title',
1516
right: 'prev,today,next',

appointment/templates/appointment/appointments.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ <h1 class="page-title">
109109
integrity="sha512-JCQkxdym6GmQ+AFVioDUq8dWaWN6tbKRhRyHvYZPupQ6DxpXzkW106FXS1ORgo/m3gxtt5lHRMqSdm2OfPajtg=="
110110
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
111111
<script>
112-
const timezone = "{{ timezone }}";
112+
const timezone = "{{ timezoneTxt }}";
113113
const locale = "{{ locale }}";
114114
const availableSlotsAjaxURL = "{% url 'appointment:available_slots_ajax' %}";
115115
const requestNextAvailableSlotURLTemplate = "{% url 'appointment:request_next_available_slot' service_id=0 %}";

appointment/tests/test_services.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ def test_available_slots(self):
471471
"""Test if available slots are returned correctly."""
472472
# On a Wednesday, the staff member should have slots from 9 AM to 5 PM
473473
slots = get_available_slots_for_staff(self.next_wednesday, self.staff_member1)
474-
expected_slots = [f"{hour:02d}:00 AM" for hour in range(9, 12)] + ["12:00 PM"] + \
475-
[f"{hour:02d}:00 PM" for hour in range(1, 5)]
474+
expected_slots = [
475+
datetime.datetime(self.next_wednesday.year, self.next_wednesday.month, self.next_wednesday.day, hour) for
476+
hour in range(9, 17)]
476477
self.assertEqual(slots, expected_slots)
477478

478479
def test_booked_slots(self):
@@ -490,7 +491,9 @@ def test_booked_slots(self):
490491

491492
# Now, the staff member should not have that slot available
492493
slots = get_available_slots_for_staff(self.next_wednesday, self.staff_member1)
493-
expected_slots = ['09:00 AM', '11:00 AM', '12:00 PM', '01:00 PM', '02:00 PM', '03:00 PM', '04:00 PM']
494+
expected_slots = [
495+
datetime.datetime(self.next_wednesday.year, self.next_wednesday.month, self.next_wednesday.day, hour, 0) for
496+
hour in range(9, 17) if hour != 10]
494497
self.assertEqual(slots, expected_slots)
495498

496499
def test_no_working_hours(self):

appointment/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ def get_available_slots_ajax(request):
9797

9898
# Check if the selected_date is today and filter out past slots
9999
if selected_date == date.today():
100-
current_time_edt = datetime.now(pytz.timezone(settings.TIME_ZONE)).time()
101-
available_slots = [slot for slot in available_slots if convert_str_to_time(slot) > current_time_edt]
100+
current_time = datetime.now(pytz.timezone(settings.TIME_ZONE)).time()
101+
available_slots = [slot for slot in available_slots if slot.time() > current_time]
102102

103-
custom_data['available_slots'] = available_slots
103+
custom_data['available_slots'] = [slot.strftime('%I:%M %p') for slot in available_slots]
104104
if len(available_slots) == 0:
105105
custom_data['error'] = True
106106
message = _('No availability')
@@ -524,7 +524,7 @@ def prepare_reschedule_appointment(request, id_request):
524524
'all_staff_members': all_staff_members,
525525
'page_title': page_title,
526526
'page_description': page_description,
527-
'available_slots': available_slots,
527+
'available_slots': [slot.strftime('%I:%M %p') for slot in available_slots],
528528
'date_chosen': date_chosen,
529529
'locale': get_locale(),
530530
'timezoneTxt': get_current_timezone_name(),

0 commit comments

Comments
 (0)