55from collections import defaultdict , namedtuple # lint-amnesty, pylint: disable=wrong-import-order
66from datetime import date , datetime , timedelta # lint-amnesty, pylint: disable=wrong-import-order
77from urllib .parse import urljoin
8+ from zoneinfo import ZoneInfo
89
910from config_models .models import ConfigurationModel
1011from django .conf import settings
2930 COURSE_UNENROLLMENT_COMPLETED ,
3031)
3132from openedx_filters .learning .filters import CourseEnrollmentStarted , CourseUnenrollmentStarted
32- from pytz import UTC
3333from requests .exceptions import HTTPError , RequestException
3434from simple_history .models import HistoricalRecords
3535
@@ -152,7 +152,7 @@ def with_certificates(self, username):
152152 """
153153 return self .filter (course_id__in = self .get_user_course_ids_with_certificates (username ))
154154
155- def in_progress (self , username , time_zone = UTC ):
155+ def in_progress (self , username , time_zone = ZoneInfo ( " UTC" ) ):
156156 """
157157 Returns a queryset of CourseEnrollment objects for courses that are currently in progress.
158158 """
@@ -170,7 +170,7 @@ def completed(self, username):
170170 """
171171 return self .active ().with_certificates (username )
172172
173- def expired (self , username , time_zone = UTC ):
173+ def expired (self , username , time_zone = ZoneInfo ( " UTC" ) ):
174174 """
175175 Returns a queryset of CourseEnrollment objects for courses that have expired.
176176 """
@@ -1087,7 +1087,7 @@ def refundable(self):
10871087 if refund_cutoff_date is None :
10881088 log .info ("Refund cutoff date is null" )
10891089 return False
1090- if datetime .now (UTC ) > refund_cutoff_date :
1090+ if datetime .now (ZoneInfo ( " UTC" ) ) > refund_cutoff_date :
10911091 log .info (f"Refund cutoff date: { refund_cutoff_date } has passed" )
10921092 return False
10931093
@@ -1133,7 +1133,10 @@ def refund_cutoff_date(self):
11331133 self .course_overview .start .replace (tzinfo = None )
11341134 )
11351135
1136- return refund_window_start_date .replace (tzinfo = UTC ) + EnrollmentRefundConfiguration .current ().refund_window
1136+ return (
1137+ refund_window_start_date .replace (tzinfo = ZoneInfo ("UTC" ))
1138+ + EnrollmentRefundConfiguration .current ().refund_window
1139+ )
11371140
11381141 def is_order_voucher_refundable (self ):
11391142 """ Checks if the coupon batch expiration date has passed to determine whether order voucher is refundable. """
@@ -1142,8 +1145,11 @@ def is_order_voucher_refundable(self):
11421145 if not vouchers :
11431146 return False
11441147 voucher_end_datetime_str = vouchers [0 ]['end_datetime' ]
1145- voucher_expiration_date = datetime .strptime (voucher_end_datetime_str , ECOMMERCE_DATE_FORMAT ).replace (tzinfo = UTC )
1146- return datetime .now (UTC ) < voucher_expiration_date
1148+ voucher_expiration_date = (
1149+ datetime .strptime (voucher_end_datetime_str , ECOMMERCE_DATE_FORMAT )
1150+ .replace (tzinfo = ZoneInfo ("UTC" ))
1151+ )
1152+ return datetime .now (ZoneInfo ("UTC" )) < voucher_expiration_date
11471153
11481154 def get_order_attribute_from_ecommerce (self , attribute_name ):
11491155 """
@@ -1265,7 +1271,7 @@ def upgrade_deadline(self):
12651271 if self .dynamic_upgrade_deadline is not None :
12661272 # When course modes expire they aren't found any more and None would be returned.
12671273 # Replicate that behavior here by returning None if the personalized deadline is in the past.
1268- if self .dynamic_upgrade_deadline <= datetime .now (UTC ):
1274+ if self .dynamic_upgrade_deadline <= datetime .now (ZoneInfo ( " UTC" ) ):
12691275 log .debug ('Schedules: Returning None since dynamic upgrade deadline has already passed.' )
12701276 return None
12711277
0 commit comments