Skip to content

Commit 4b802dc

Browse files
committed
delete settings.get_timezone
It's not needed since settings.TIME_ZONE can be used and is guaranteed to exist and be valid.
1 parent bce6349 commit 4b802dc

File tree

5 files changed

+6
-26
lines changed

5 files changed

+6
-26
lines changed

appointment/tests/test_utils.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from appointment.services import get_available_slots, get_finish_button_text
1717
from appointment.settings import APPOINTMENT_BUFFER_TIME, APPOINTMENT_FINISH_TIME, APPOINTMENT_LEAD_TIME, \
1818
APPOINTMENT_SLOT_DURATION, APPOINTMENT_WEBSITE_NAME
19-
from appointment.utils.date_time import combine_date_and_time, convert_str_to_date, get_current_year, get_timestamp, \
20-
get_timezone
19+
from appointment.utils.date_time import combine_date_and_time, convert_str_to_date, get_current_year, get_timestamp
2120
from appointment.utils.db_helpers import get_appointment_buffer_time, get_appointment_finish_time, \
2221
get_appointment_lead_time, get_appointment_slot_duration, get_user_model, get_website_name
2322
from appointment.utils.view_helpers import generate_random_id, get_locale, is_ajax
@@ -127,10 +126,6 @@ def test_get_locale_others(self):
127126
def test_get_current_year(self):
128127
self.assertEqual(get_current_year(), datetime.datetime.now().year)
129128

130-
# Test cases for get_timezone
131-
def test_get_timezone(self):
132-
self.assertIsNotNone(get_timezone())
133-
134129
# Test cases for convert_str_to_date
135130
def test_convert_str_to_date_valid(self):
136131
date_str = '2023-07-31'

appointment/tests/utils/test_date_time.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from appointment.utils.date_time import (
1111
combine_date_and_time, convert_12_hour_time_to_24_hour_time, convert_24_hour_time_to_12_hour_time,
1212
convert_minutes_in_human_readable_format, convert_str_to_date,
13-
convert_str_to_time, get_ar_end_time, get_current_year, get_timestamp, get_timezone, get_weekday_num,
13+
convert_str_to_time, get_ar_end_time, get_current_year, get_timestamp, get_weekday_num,
1414
time_difference
1515
)
1616

@@ -378,10 +378,6 @@ def test_get_timestamp(self, mock_now):
378378

379379

380380
class GeneralDateTimeTests(TestCase):
381-
def test_get_timezone(self):
382-
"""Test get_timezone function"""
383-
self.assertEqual(get_timezone(), APP_TIME_ZONE)
384-
385381
def test_get_current_year(self):
386382
"""Test get_current_year function"""
387383
self.assertEqual(get_current_year(), datetime.datetime.now().year)
@@ -392,11 +388,6 @@ def test_get_current_year_mocked(self):
392388
mock_date.now.return_value.year = 1999 # Setting year attribute of the mock object
393389
self.assertEqual(get_current_year(), 1999)
394390

395-
@patch('appointment.utils.date_time.APP_TIME_ZONE', new="Asia/Tokyo")
396-
def test_get_timezone_with_modified_setting(self):
397-
"""Test get_timezone function with a modified timezone setting."""
398-
self.assertEqual(get_timezone(), "Asia/Tokyo")
399-
400391
def test_get_weekday_num(self):
401392
"""Test get_weekday_num function with valid input"""
402393
self.assertEqual(get_weekday_num("Monday"), 1)

appointment/utils/date_time.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ def get_ar_end_time(start_time, duration) -> datetime.time:
180180
return dt_end_time.time()
181181

182182

183-
def get_timezone() -> str:
184-
"""Return the current timezone of the application."""
185-
return APP_TIME_ZONE
186-
187-
188183
def get_timestamp() -> str:
189184
"""Get the current timestamp as a string without the decimal part.
190185

appointment/utils/json_context.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
from django.http import JsonResponse
1111
from django.shortcuts import render
1212
from django.urls import reverse
13+
from django.conf import settings
1314

1415
from appointment.settings import APPOINTMENT_ADMIN_BASE_TEMPLATE, APPOINTMENT_BASE_TEMPLATE
15-
from appointment.utils.date_time import get_timezone
1616
from appointment.utils.db_helpers import username_in_user_model
1717
from appointment.utils.error_codes import ErrorCode
1818

1919

2020
def convert_appointment_to_json(request, appointments: list) -> list:
2121
"""Convert a queryset of Appointment objects to a JSON serializable format."""
2222
su = request.user.is_superuser
23-
tz = pytz.timezone(get_timezone())
23+
tz = pytz.timezone(settings.TIME_ZONE)
2424
return [{
2525
"id": appt.id,
2626
"client": appt.client.username if username_in_user_model() else "",
@@ -36,7 +36,7 @@ def convert_appointment_to_json(request, appointments: list) -> list:
3636
"service_id": appt.get_service().id,
3737
"additional_info": appt.additional_info,
3838
"want_reminder": appt.want_reminder,
39-
"timezone": get_timezone(),
39+
"timezone": settings.TIME_ZONE,
4040
} for appt in appointments]
4141

4242

@@ -58,7 +58,7 @@ def get_generic_context(request, admin=True):
5858
return {
5959
'BASE_TEMPLATE': APPOINTMENT_ADMIN_BASE_TEMPLATE if admin else APPOINTMENT_BASE_TEMPLATE,
6060
'user': request.user,
61-
'timezone': get_timezone(),
61+
'timezone': settings.TIME_ZONE,
6262
}
6363

6464

docs/utils/date_time.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ system.
2626
## Date Time Utilities:
2727

2828
- **get_ar_end_time**: Calculate the end time of an appointment request based on its start time and duration.
29-
- **get_timezone**: Retrieve the current timezone of the application.
3029
- **get_timestamp**: Obtain the current timestamp as a string without the decimal part.
3130
- **time_difference**: Calculate the difference between two times.
3231

0 commit comments

Comments
 (0)