diff --git a/README.rst b/README.rst index 8c3d203..2775afb 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ Overview ======== -`fiscalyear `_ is a small, lightweight Python module providing helpful utilities for managing the fiscal calendar. It is designed as an extension of the built-in `datetime `_ and `calendar `_ modules, adding the ability to query the fiscal year and fiscal quarter of a date or datetime object. +`fiscalyear `_ is a small, lightweight Python module providing helpful utilities for managing the fiscal calendar. It is designed as an extension of the built-in `datetime `_ and `calendar `_ modules, adding the ability to query the fiscal year, fiscal month, and fiscal quarter of a date or datetime object. Basic Usage @@ -83,7 +83,7 @@ You can also get the current ``FiscalQuarter`` with: FiscalDateTime -------------- -The start and end of each quarter are stored as instances of the ``FiscalDateTime`` class. This class provides all of the same features as the ``datetime`` class, with the addition of the ability to query the fiscal year and quarter. +The start and end of each quarter are stored as instances of the ``FiscalDateTime`` class. This class provides all of the same features as the ``datetime`` class, with the addition of the ability to query the fiscal year, fiscal month, and quarter. .. code-block:: python @@ -92,6 +92,8 @@ The start and end of each quarter are stored as instances of the ``FiscalDateTim FiscalDateTime(2017, 4, 8, 20, 30, 31, 105323) >>> c.fiscal_year 2017 + >>> c.fiscal_month + 7 >>> c.quarter 3 >>> c.next_quarter diff --git a/docs/basic_usage.rst b/docs/basic_usage.rst index 4588730..65996fb 100644 --- a/docs/basic_usage.rst +++ b/docs/basic_usage.rst @@ -64,7 +64,7 @@ You can also get the current ``FiscalQuarter`` with: FiscalDateTime -------------- -The start and end of each quarter are stored as instances of the ``FiscalDateTime`` class. This class provides all of the same features as the ``datetime`` class, with the addition of the ability to query the fiscal year and quarter. +The start and end of each quarter are stored as instances of the ``FiscalDateTime`` class. This class provides all of the same features as the ``datetime`` class, with the addition of the ability to query the fiscal year, fiscal month, and quarter. .. code-block:: python @@ -73,6 +73,8 @@ The start and end of each quarter are stored as instances of the ``FiscalDateTim FiscalDateTime(2017, 4, 8, 20, 30, 31, 105323) >>> c.fiscal_year 2017 + >>> c.fiscal_month + 7 >>> c.quarter 3 >>> c.next_quarter diff --git a/docs/index.rst b/docs/index.rst index 4a132b9..2a89fa5 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,7 +1,7 @@ fiscalyear ========== -`fiscalyear `_ is a small, lightweight Python module providing helpful utilities for managing the fiscal calendar. It is designed as an extension of the built-in `datetime `_ and `calendar `_ modules, adding the ability to query the fiscal year and fiscal quarter of a date or datetime object. +`fiscalyear `_ is a small, lightweight Python module providing helpful utilities for managing the fiscal calendar. It is designed as an extension of the built-in `datetime `_ and `calendar `_ modules, adding the ability to query the fiscal year, fiscal month, and fiscal quarter of a date or datetime object. .. toctree:: diff --git a/fiscalyear.py b/fiscalyear.py index 770e5f5..431d1e2 100644 --- a/fiscalyear.py +++ b/fiscalyear.py @@ -623,6 +623,13 @@ def fiscal_year(self): elif self in FiscalYear(self.year - 1): return self.year - 1 + @property + def fiscal_month(self): + """:returns: The fiscal month + :rtype: int + """ + return (self.month - FiscalYear(self.year).start.month) % 12 + 1 + @property def prev_fiscal_year(self): """:returns: The previous fiscal year diff --git a/requirements.txt b/requirements.txt index 228f95a..8044c07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ codecov -pytest +pytest~=4.6 pytest-cov -pytest-mock +pytest-mock~=2.0 pytest-runner sphinx sphinx_rtd_theme diff --git a/test_fiscalyear.py b/test_fiscalyear.py index f80953c..b9214af 100644 --- a/test_fiscalyear.py +++ b/test_fiscalyear.py @@ -668,16 +668,22 @@ def test_basic(self, a): assert a.day == 1 assert a.fiscal_year == 2017 + assert a.fiscal_month == 4 assert a.quarter == 2 - def test_fiscal_year(self, a, c): + def test_fiscal_periods(self, a, c): with fiscalyear.fiscal_calendar(*US_FEDERAL): assert a.fiscal_year == 2017 + assert a.fiscal_month == 4 assert c.fiscal_year == 2018 + assert c.fiscal_month == 2 + with fiscalyear.fiscal_calendar(*UK_PERSONAL): assert a.fiscal_year == 2016 + assert a.fiscal_month == 10 assert c.fiscal_year == 2017 + assert c.fiscal_month == 8 def test_prev_fiscal_year(self, a): assert a.prev_fiscal_year == fiscalyear.FiscalYear(2016) @@ -719,14 +725,18 @@ def test_basic(self, a): assert a.fiscal_year == 2017 assert a.quarter == 2 - def test_fiscal_year(self, a, c): + def test_fiscal_periods(self, a, c): with fiscalyear.fiscal_calendar(*US_FEDERAL): assert a.fiscal_year == 2017 + assert a.fiscal_month == 4 assert c.fiscal_year == 2018 + assert c.fiscal_month == 2 with fiscalyear.fiscal_calendar(*UK_PERSONAL): assert a.fiscal_year == 2016 + assert a.fiscal_month == 10 assert c.fiscal_year == 2017 + assert c.fiscal_month == 8 def test_prev_fiscal_year(self, a): assert a.prev_fiscal_year == fiscalyear.FiscalYear(2016)