Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix share expiration date calculation for end-of-month days #1594

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions backend/dataall/base/utils/expiration_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ class ExpirationUtils:
def calculate_expiry_date(expirationPeriod, expirySetting):
currentDate = date.today()
if expirySetting == Expiration.Quartely.value:
quarterlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod * 3 - 1)
if currentDate < datetime(currentDate.year, currentDate.month, 15).date():
# First half of the month - extend 2.X months
quarterlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod * 3 - 1)
else:
# Second half of the month - extend 3.X months
quarterlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod * 3)
day = calendar.monthrange(quarterlyCalculatedDate.year, quarterlyCalculatedDate.month)[1]
shareExpiryDate = datetime(quarterlyCalculatedDate.year, quarterlyCalculatedDate.month, day)
elif expirySetting == Expiration.Monthly.value:
monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod - 1)
if currentDate < datetime(currentDate.year, currentDate.month, 15).date():
# First half of the month - extend until end of month
monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod - 1)
else:
# Second half of the month - extend until end of next month
monthlyCalculatedDate = currentDate + relativedelta(months=expirationPeriod)
monthEndDay = calendar.monthrange(monthlyCalculatedDate.year, monthlyCalculatedDate.month)[1]
shareExpiryDate = datetime(monthlyCalculatedDate.year, monthlyCalculatedDate.month, monthEndDay)
else:
Expand Down
Loading