Skip to content

Commit 175888d

Browse files
authored
Merge pull request #158 from deronnax/timezone-utils
delete get_timezone and APP_TIME_ZONE
2 parents 078d0ca + e2a4aee commit 175888d

File tree

8 files changed

+11
-35
lines changed

8 files changed

+11
-35
lines changed

appointment/settings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
APPOINTMENT_LEAD_TIME = getattr(settings, 'APPOINTMENT_LEAD_TIME', (9, 0))
2222
APPOINTMENT_FINISH_TIME = getattr(settings, 'APPOINTMENT_FINISH_TIME', (18, 30))
2323
APP_DEFAULT_FROM_EMAIL = getattr(settings, 'DEFAULT_FROM_EMAIL', DEFAULT_FROM_EMAIL)
24-
APP_TIME_ZONE = getattr(settings, 'TIME_ZONE', 'America/New_York')
2524

2625

2726
def check_q_cluster():

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 & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
from django.test import TestCase
88

9-
from appointment.settings import APP_TIME_ZONE
109
from appointment.utils.date_time import (
1110
combine_date_and_time, convert_12_hour_time_to_24_hour_time, convert_24_hour_time_to_12_hour_time,
1211
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,
12+
convert_str_to_time, get_ar_end_time, get_current_year, get_timestamp, get_weekday_num,
1413
time_difference
1514
)
1615

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

379378

380379
class GeneralDateTimeTests(TestCase):
381-
def test_get_timezone(self):
382-
"""Test get_timezone function"""
383-
self.assertEqual(get_timezone(), APP_TIME_ZONE)
384-
385380
def test_get_current_year(self):
386381
"""Test get_current_year function"""
387382
self.assertEqual(get_current_year(), datetime.datetime.now().year)
@@ -392,11 +387,6 @@ def test_get_current_year_mocked(self):
392387
mock_date.now.return_value.year = 1999 # Setting year attribute of the mock object
393388
self.assertEqual(get_current_year(), 1999)
394389

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-
400390
def test_get_weekday_num(self):
401391
"""Test get_weekday_num function with valid input"""
402392
self.assertEqual(get_weekday_num("Monday"), 1)

appointment/utils/date_time.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from django.utils import timezone
1212
from django.utils.translation import gettext_lazy as _, ngettext
1313

14-
from appointment.settings import APP_TIME_ZONE
15-
1614

1715
def combine_date_and_time(date, time) -> datetime.datetime:
1816
"""Combine a date and a time into a datetime object.
@@ -180,11 +178,6 @@ def get_ar_end_time(start_time, duration) -> datetime.time:
180178
return dt_end_time.time()
181179

182180

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

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 "",
@@ -37,7 +37,7 @@ def convert_appointment_to_json(request, appointments: list) -> list:
3737
"staff_id": appt.appointment_request.staff_member.id,
3838
"additional_info": appt.additional_info,
3939
"want_reminder": appt.want_reminder,
40-
"timezone": get_timezone(),
40+
"timezone": settings.TIME_ZONE,
4141
} for appt in appointments]
4242

4343

@@ -59,7 +59,7 @@ def get_generic_context(request, admin=True):
5959
return {
6060
'BASE_TEMPLATE': APPOINTMENT_ADMIN_BASE_TEMPLATE if admin else APPOINTMENT_BASE_TEMPLATE,
6161
'user': request.user,
62-
'timezone': get_timezone(),
62+
'timezone': settings.TIME_ZONE,
6363
'is_superuser': request.user.is_superuser,
6464
}
6565

appointment/utils/view_helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
import uuid
1010

11+
from django.conf import settings
1112
from django.utils.translation import get_language, to_locale
1213

13-
from appointment.settings import APP_TIME_ZONE
14-
1514

1615
def get_locale() -> str:
1716
"""Get the current locale based on the user's language settings, without the country code.
@@ -49,7 +48,7 @@ def get_timezone_txt() -> str:
4948
5049
:return: The current timezone in a string format.
5150
"""
52-
tmz = APP_TIME_ZONE
51+
tmz = settings.TIME_ZONE
5352
timezone_map = {
5453
'UTC': 'Universal Time Coordinated (UTC)',
5554
'US/Eastern': 'Eastern Daylight Time (US & Canada)',

appointment/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datetime import date, datetime, timedelta
1010

1111
import pytz
12+
from django.conf import settings
1213
from django.contrib import messages
1314
from django.contrib.auth import login
1415
from django.contrib.auth.forms import SetPasswordForm
@@ -41,7 +42,7 @@
4142
from .decorators import require_ajax
4243
from .messages_ import passwd_error, passwd_set_successfully
4344
from .services import get_appointments_and_slots, get_available_slots_for_staff
44-
from .settings import (APPOINTMENT_PAYMENT_URL, APPOINTMENT_THANK_YOU_URL, APP_TIME_ZONE)
45+
from .settings import (APPOINTMENT_PAYMENT_URL, APPOINTMENT_THANK_YOU_URL)
4546
from .utils.date_time import convert_str_to_date, convert_str_to_time
4647
from .utils.error_codes import ErrorCode
4748
from .utils.json_context import get_generic_context_with_extra, json_response
@@ -96,7 +97,7 @@ def get_available_slots_ajax(request):
9697
# Check if the selected_date is today and filter out past slots
9798
if selected_date == date.today():
9899
# Get the current time in EDT timezone
99-
current_time_edt = datetime.now(pytz.timezone(APP_TIME_ZONE)).time()
100+
current_time_edt = datetime.now(pytz.timezone(settings.TIME_ZONE)).time()
100101
available_slots = [slot for slot in available_slots if convert_str_to_time(slot) > current_time_edt]
101102

102103
custom_data['available_slots'] = available_slots

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)