Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danangmassandy committed Feb 4, 2025
1 parent dad5b24 commit 5a9bfdd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
1 change: 0 additions & 1 deletion django_project/core/tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,3 @@ def test_same_start_and_end(self):
split_epochs_by_year_month(int(start_epoch), int(start_epoch)),
expected
)

23 changes: 17 additions & 6 deletions django_project/core/utils/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,28 @@ def split_epochs_by_year_month(start_epoch, end_epoch):

current_year, current_month = start_dt.year, start_dt.month
while (current_year, current_month) <= (end_dt.year, end_dt.month):
month_start = datetime(current_year, current_month, 1, tzinfo=timezone.utc).timestamp()

month_start = datetime(
current_year, current_month, 1, tzinfo=timezone.utc
).timestamp()

if current_month == 12:
month_end = datetime(current_year + 1, 1, 1, tzinfo=timezone.utc).timestamp() - 1 # Last second of the month
# Last second of the month
month_end = datetime(
current_year + 1, 1, 1,
tzinfo=timezone.utc
).timestamp() - 1
else:
month_end = datetime(current_year, current_month + 1, 1, tzinfo=timezone.utc).timestamp() - 1

month_end = datetime(
current_year, current_month + 1, 1,
tzinfo=timezone.utc
).timestamp() - 1

start = max(start_epoch, month_start)
end = min(end_epoch, month_end)

results.append((current_year, current_month, int(start), int(end)))
results.append(
(current_year, current_month, int(start), int(end))
)

# Move to next month
if current_month == 12:
Expand Down

0 comments on commit 5a9bfdd

Please sign in to comment.