Skip to content

Commit

Permalink
Merge pull request #11 from nicmendoza/master
Browse files Browse the repository at this point in the history
Add fiscal_month attribute to FiscalDateTime and FiscalDate
  • Loading branch information
adamjstewart authored Oct 16, 2020
2 parents 365f86e + 75c2e2d commit d6e0274
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Overview
========

`fiscalyear <https://github.com/adamjstewart/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 <https://docs.python.org/3/library/datetime.html>`_ and `calendar <https://docs.python.org/3/library/calendar.html>`_ modules, adding the ability to query the fiscal year and fiscal quarter of a date or datetime object.
`fiscalyear <https://github.com/adamjstewart/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 <https://docs.python.org/3/library/datetime.html>`_ and `calendar <https://docs.python.org/3/library/calendar.html>`_ modules, adding the ability to query the fiscal year, fiscal month, and fiscal quarter of a date or datetime object.


Basic Usage
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fiscalyear
==========

`fiscalyear <https://github.com/adamjstewart/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 <https://docs.python.org/3/library/datetime.html>`_ and `calendar <https://docs.python.org/3/library/calendar.html>`_ modules, adding the ability to query the fiscal year and fiscal quarter of a date or datetime object.
`fiscalyear <https://github.com/adamjstewart/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 <https://docs.python.org/3/library/datetime.html>`_ and `calendar <https://docs.python.org/3/library/calendar.html>`_ modules, adding the ability to query the fiscal year, fiscal month, and fiscal quarter of a date or datetime object.


.. toctree::
Expand Down
7 changes: 7 additions & 0 deletions fiscalyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
codecov
pytest
pytest~=4.6
pytest-cov
pytest-mock
pytest-mock~=2.0
pytest-runner
sphinx
sphinx_rtd_theme
14 changes: 12 additions & 2 deletions test_fiscalyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d6e0274

Please sign in to comment.