Rename method to get start and end date of a month for clarity

This commit is contained in:
Imdad Ahad
2017-08-10 16:29:13 +01:00
parent 19b09f2a27
commit 782f3ea693
3 changed files with 13 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ def get_april_fools(year):
tzinfo=None)
def get_month_start_end_date(month_year):
def get_month_start_and_end_date_in_utc(month_year):
"""
This function return the start and date of the month_year as UTC,
:param month_year: the datetime to calculate the start and end date for that month

View File

@@ -8,7 +8,7 @@ Create Date: 2017-07-12 13:35:45.636618
from datetime import datetime
from alembic import op
import sqlalchemy as sa
from app.dao.date_util import get_month_start_end_date
from app.dao.date_util import get_month_start_and_end_date_in_utc
down_revision = '0111_drop_old_service_flags'
revision = '0112_add_start_end_dates'
@@ -24,7 +24,7 @@ def upgrade():
results = conn.execute("Select id, month, year from monthly_billing")
res = results.fetchall()
for x in res:
start_date, end_date = get_month_start_end_date(
start_date, end_date = get_month_start_and_end_date_in_utc(
datetime(int(x.year), datetime.strptime(x.month, '%B').month, 1))
conn.execute("update monthly_billing set start_date = '{}', end_date = '{}' where id = '{}'".format(start_date,
end_date,

View File

@@ -2,7 +2,7 @@ from datetime import datetime
import pytest
from app.dao.date_util import get_financial_year, get_april_fools, get_month_start_end_date
from app.dao.date_util import get_financial_year, get_april_fools, get_month_start_and_end_date_in_utc
def test_get_financial_year():
@@ -17,15 +17,15 @@ def test_get_april_fools():
assert april_fools.tzinfo is None
@pytest.mark.parametrize("month, year, expected_start, expected_end",
[
(7, 2017, datetime(2017, 6, 30, 23, 00, 00), datetime(2017, 7, 31, 22, 59, 59, 99999)),
(2, 2016, datetime(2016, 2, 1, 00, 00, 00), datetime(2016, 2, 29, 23, 59, 59, 99999)),
(2, 2017, datetime(2017, 2, 1, 00, 00, 00), datetime(2017, 2, 28, 23, 59, 59, 99999)),
(9, 2018, datetime(2018, 8, 31, 23, 00, 00), datetime(2018, 9, 30, 22, 59, 59, 99999)),
(12, 2019, datetime(2019, 12, 1, 00, 00, 00), datetime(2019, 12, 31, 23, 59, 59, 99999))])
def test_get_month_start_end_date(month, year, expected_start, expected_end):
@pytest.mark.parametrize("month, year, expected_start, expected_end", [
(7, 2017, datetime(2017, 6, 30, 23, 00, 00), datetime(2017, 7, 31, 22, 59, 59, 99999)),
(2, 2016, datetime(2016, 2, 1, 00, 00, 00), datetime(2016, 2, 29, 23, 59, 59, 99999)),
(2, 2017, datetime(2017, 2, 1, 00, 00, 00), datetime(2017, 2, 28, 23, 59, 59, 99999)),
(9, 2018, datetime(2018, 8, 31, 23, 00, 00), datetime(2018, 9, 30, 22, 59, 59, 99999)),
(12, 2019, datetime(2019, 12, 1, 00, 00, 00), datetime(2019, 12, 31, 23, 59, 59, 99999))
])
def test_get_month_start_and_end_date_in_utc(month, year, expected_start, expected_end):
month_year = datetime(year, month, 10, 13, 30, 00)
result = get_month_start_end_date(month_year)
result = get_month_start_and_end_date_in_utc(month_year)
assert result[0] == expected_start
assert result[1] == expected_end