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

Add fiscal_month attribute to FiscalDateTime and FiscalDate #11

Merged
merged 13 commits into from
Oct 16, 2020
Merged
2 changes: 1 addition & 1 deletion 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.
nicmendoza marked this conversation as resolved.
Show resolved Hide resolved


Basic Usage
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.
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved

.. 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
nicmendoza marked this conversation as resolved.
Show resolved Hide resolved
>>> 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.
nicmendoza marked this conversation as resolved.
Show resolved Hide resolved


.. 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):
nicmendoza marked this conversation as resolved.
Show resolved Hide resolved
""":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