Skip to content

Commit

Permalink
DRAFT: COST-4175 - Fix AWS first of the month issue
Browse files Browse the repository at this point in the history
  • Loading branch information
esebesto committed Feb 2, 2024
1 parent 6595d0a commit 5e16168
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 5 additions & 1 deletion nise/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,11 @@ def _load_static_report_data(options):
start_dates.append(generated_start_date)
if attributes.get("end_date"):
generated_end_date = calculate_end_date(generated_start_date, attributes.get("end_date"))
elif options.get("end_date") and options.get("end_date").date() != today().date():

elif options.get("end_date") and (
options.get("end_date").date() != today().date()
or (isinstance(options.get("end_date"), datetime.datetime) and options.get("end_date").hour != 0)
):
generated_end_date = calculate_end_date(generated_start_date, options.get("end_date"))
else:
generated_end_date = today()
Expand Down
23 changes: 10 additions & 13 deletions nise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,31 +501,29 @@ def _create_generator_dates_from_yaml(attributes, month):
gen_start_date = None
gen_end_date = None

# distinguish real month end from "fake" month end (i.e, first of the following month)
if month.get("end").day != 1:
month_end_to_compare = month.get("end").replace(hour=23, minute=59, second=59)
else:
month_end_to_compare = month.get("end")

Check warning on line 508 in nise/report.py

View check run for this annotation

Codecov / codecov/patch

nise/report.py#L508

Added line #L508 was not covered by tests

# Generator range is larger then current month on both start and end
if attributes.get("start_date") < month.get("start") and attributes.get("end_date") > month.get("end").replace(
hour=23, minute=59, second=59
):
if attributes.get("start_date") < month.get("start") and attributes.get("end_date") > month_end_to_compare:
gen_start_date = month.get("start")
gen_end_date = month.get("end")

# Generator starts before month start and ends within month
if attributes.get("start_date") <= month.get("start") and attributes.get("end_date") <= month.get("end").replace(
hour=23, minute=59, second=59
):
elif attributes.get("start_date") < month.get("start") and attributes.get("end_date") <= month_end_to_compare:
gen_start_date = month.get("start")
gen_end_date = attributes.get("end_date")

# Generator is within month
if attributes.get("start_date") >= month.get("start") and attributes.get("end_date") <= month.get("end").replace(
hour=23, minute=59, second=59
):
elif attributes.get("start_date") >= month.get("start") and attributes.get("end_date") <= month_end_to_compare:
gen_start_date = attributes.get("start_date")
gen_end_date = attributes.get("end_date")

# Generator starts within month and ends in next month
if attributes.get("start_date") >= month.get("start") and attributes.get("end_date") > month.get("end").replace(
hour=23, minute=59, second=59
):
elif attributes.get("start_date") >= month.get("start") and attributes.get("end_date") > month_end_to_compare:
gen_start_date = attributes.get("start_date")
gen_end_date = month.get("end")

Expand Down Expand Up @@ -593,7 +591,6 @@ def aws_create_marketplace_report(options): # noqa: C901

def aws_create_report(options): # noqa: C901
"""Create a cost usage report file."""
data = []
start_date = options.get("start_date")
end_date = options.get("end_date")
aws_finalize_report = options.get("aws_finalize_report")
Expand Down

0 comments on commit 5e16168

Please sign in to comment.