-
Notifications
You must be signed in to change notification settings - Fork 180
Description
π Thank you X 1,000,000 for this AH-MAZING course! It has been life changing!
According to the datetime docs:
timedelta.max
The most positive timedelta object, timedelta(days=999999999, hours=23, minutes=59, seconds=59, microseconds=999999).
In the by_range
, by_days_left
and by_days_ago
methods in the UserSubscriptionQuerySet
, we set the range_end
, day_end
and day_end
, respectively, using microseconds=59
. In order to get the max, should we not actually use microseconds=999999
?
This results in end of day being off by 999940 microseconds. I'm sure this is not a big deal but wanted to bring it your attention.
For example, currently when I run:
python manage.py sync_user_subs --day-start 0 --day-end 0
I get:
Sync active subs
Range is 2024-06-30 00:00:00+00:00 to 2024-06-30 23:59:59.000059+00:00
Done
When I change the code to:
class UserSubscriptionQuerySet(models.QuerySet):
def by_range(self, days_start=7, days_end=120, verbose=True):
...
range_end = days_end_from_now.replace(hour=23, minute=59, second=59, microsecond=999999)
...
def by_days_left(self, days_left=7):
...
day_end = in_n_days.replace(hour=23, minute=59, second=59, microsecond=999999)
...
def by_days_ago(self, days_ago=3):
...
day_end = in_n_days.replace(hour=23, minute=59, second=59, microsecond=999999)
...
I am able to get the expected result:
Sync active subs
Range is 2024-06-30 00:00:00+00:00 to 2024-06-30 23:59:59.999999+00:00
Done
Thanks @jmitchel3 and @codingforentrepreneurs for the tremendous amount of time, energy and effort you put into this course. I can't wait to continue learning from your content π !