Skip to content

Commit 0e5843f

Browse files
Altering Calendar picker to use the date time utils
1 parent 9463b23 commit 0e5843f

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

tests/test_calendar_picker_methods.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from playwright.sync_api import Page
1010
from pages.base_page import BasePage
1111
from utils.user_tools import UserTools
12+
from utils.date_time_utils import DateTimeUtils
1213
from datetime import datetime
1314
from sys import platform
1415

@@ -57,9 +58,9 @@ def test_calender_picker_v2(page: Page) -> None:
5758
ActiveBatchList(page).enter_deadline_date_filter(datetime.today())
5859
if platform == "win32": # Windows
5960
ActiveBatchList(page).verify_deadline_date_filter_input(
60-
str(datetime.today().strftime("%#d %b %Y"))
61+
str(DateTimeUtils.format_date(datetime.today(), "%#d %b %Y"))
6162
)
6263
else: # Linux or Mac
6364
ActiveBatchList(page).verify_deadline_date_filter_input(
64-
str(datetime.today().strftime("%-d %b %Y"))
65+
str(DateTimeUtils.format_date(datetime.today(), "%-d %b %Y"))
6566
)

tests_utils/test_calendar_picker_util.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ def test_calculate_v2_calendar_variables(page: Page):
3838
month_short,
3939
current_year,
4040
year,
41-
end_of_current_decade,
4241
current_decade,
4342
decade,
44-
end_of_current_century,
4543
current_century,
4644
century,
4745
) = calendar_picker.calculate_v2_calendar_variables(
@@ -53,10 +51,8 @@ def test_calculate_v2_calendar_variables(page: Page):
5351
assert month_short == "Jan"
5452
assert current_year == 2020
5553
assert year == 1963
56-
assert end_of_current_decade == "2029"
5754
assert current_decade == 2020
5855
assert decade == 1960
59-
assert end_of_current_century == "2090"
6056
assert current_century == 2000
6157
assert century == 1900
6258

@@ -66,10 +62,8 @@ def test_calculate_v2_calendar_variables(page: Page):
6662
month_short,
6763
current_year,
6864
year,
69-
end_of_current_decade,
7065
current_decade,
7166
decade,
72-
end_of_current_century,
7367
current_century,
7468
century,
7569
) = calendar_picker.calculate_v2_calendar_variables(
@@ -81,10 +75,8 @@ def test_calculate_v2_calendar_variables(page: Page):
8175
assert month_short == "Dec"
8276
assert current_year == 2020
8377
assert year == 2356
84-
assert end_of_current_decade == "2029"
8578
assert current_decade == 2020
8679
assert decade == 2350
87-
assert end_of_current_century == "2090"
8880
assert current_century == 2000
8981
assert century == 2300
9082

utils/calendar_picker.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ def calculate_years_and_months_to_traverse(
6565
This function is used when using the v1 calendar picker
6666
It calculates how many years and months it needs to traverse
6767
"""
68-
years_to_traverse = int(current_date.strftime("%Y")) - int(date.strftime("%Y"))
69-
months_to_traverse = int(current_date.strftime("%m")) - int(date.strftime("%m"))
68+
years_to_traverse = int(DateTimeUtils.format_date(current_date, "%Y")) - int(
69+
DateTimeUtils.format_date(date, "%Y")
70+
)
71+
months_to_traverse = int(DateTimeUtils.format_date(current_date, "%m")) - int(
72+
DateTimeUtils.format_date(date, "%m")
73+
)
7074
return years_to_traverse, months_to_traverse
7175

7276
def traverse_years_in_v1_calendar(self, years_to_traverse: int) -> None:
@@ -97,9 +101,9 @@ def select_day(self, date: datetime) -> None:
97101
It extracts the day from the date and then selects that value in the calendar picker
98102
"""
99103
if platform == "win32": # Windows
100-
day_to_select = str(date.strftime("%#d"))
104+
day_to_select = DateTimeUtils.format_date(date, "%#d")
101105
else: # Linux or Mac
102-
day_to_select = str(date.strftime("%-d"))
106+
day_to_select = DateTimeUtils.format_date(date, "%-d")
103107
number_of_cells_with_day = self.page.get_by_role(
104108
"cell", name=day_to_select
105109
).count()
@@ -152,18 +156,18 @@ def calculate_v2_calendar_variables(
152156
current_century: the current century in yyyy format (e.g. 2000/2100)
153157
century: the wanted century in yyyy format (e.g. 1900)
154158
"""
155-
current_month_long = str(current_date.strftime("%B"))
156-
current_year = int(current_date.strftime("%Y"))
159+
current_month_long = DateTimeUtils.format_date(current_date, "%B")
160+
current_year = int(DateTimeUtils.format_date(current_date, "%Y"))
157161
current_century = (current_year // 100) * 100
158162
current_decade = (
159163
((current_year - current_century) // 10) * 10
160164
) + current_century
161165

162-
year = int(date.strftime("%Y"))
166+
year = int(DateTimeUtils.format_date(date, "%Y"))
163167
century = (year // 100) * 100
164168
decade = (((year - century) // 10) * 10) + century
165-
month_short = str(date.strftime("%b"))
166-
month_long = str(date.strftime("%B"))
169+
month_short = DateTimeUtils.format_date(date, "%b")
170+
month_long = DateTimeUtils.format_date(date, "%B")
167171

168172
return (
169173
current_month_long,
@@ -300,9 +304,9 @@ def book_first_eligble_appointment(
300304
current_month_displayed
301305
)
302306
if platform == "win32": # Windows
303-
current_month_int = int(datetime.now().strftime("%#m"))
307+
current_month_int = int(DateTimeUtils.format_date(datetime.now(), "%#m"))
304308
else: # Linux or Mac
305-
current_month_int = int(datetime.now().strftime("%-m"))
309+
current_month_int = int(DateTimeUtils.format_date(datetime.now(), "%-m"))
306310

307311
self.book_appointments_go_to_month(
308312
current_month_displayed_int, current_month_int

0 commit comments

Comments
 (0)