Repository: adamjstewart/fiscalyear

Issue:
Syntactic sugar for getting the current Fiscal{Year,Quarter}
I think it would be nice if there was an easy way to get the current `FiscalYear`/`FiscalQuarter`.

This could easily be achieved by using a couple of `classmethods`. E.g.:

``` diff
$ git diff
diff --git a/fiscalyear.py b/fiscalyear.py
index c6f8ddc..f7213d7 100644
--- a/fiscalyear.py
+++ b/fiscalyear.py
@@ -191,6 +191,11 @@ class FiscalYear(object):
         self._fiscal_year = fiscal_year
         return self
 
+    @classmethod
+    def current(cls):
+        today = datetime.date.today()
+        return cls(today.year)
+
     def __repr__(self):
         """Convert to formal string, for repr().
 
@@ -371,6 +376,11 @@ class FiscalQuarter(object):
         self._quarter = quarter
         return self
 
+    @classmethod
+    def current(cls):
+        today = datetime.date.today()
+        return cls(today.year, (today.month // 3) + 1)
+
     def __repr__(self):
         """Convert to formal string, for repr().
```

This way you could write: 
``` python
In [3]: FiscalYear.current()
Out[3]: FiscalYear(2018)

In [4]: FiscalQuarter.current()
Out[4]: FiscalQuarter(2018, 1)
```

If you want, I can try to make a pull request.

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 416d131..f829e95 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,13 @@
 language: python
 
-dist: xenial
-
 python:
+  - 2.6
   - 2.7
+  - 3.3
   - 3.4
   - 3.5
   - 3.6
-  - 3.7
-  - 3.8-dev
 
-script: pytest --cov=fiscalyear
+script: py.test --cov=fiscalyear
 
 after_success: codecov
diff --git a/LICENSE b/LICENSE
index f2c31c2..247c0b8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 MIT License
 
-Copyright (c) 2017-2019 Adam J. Stewart
+Copyright (c) 2017 Adam J. Stewart
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.rst b/README.rst
index b7d0874..2fe25dc 100644
--- a/README.rst
+++ b/README.rst
@@ -26,13 +26,18 @@ The ``FiscalYear`` class provides an object for storing information about the st
 
 .. code-block:: python
 
-   >>> from fiscalyear import *
    >>> a = FiscalYear(2017)
    >>> a.start
    FiscalDateTime(2016, 10, 1, 0, 0)
    >>> a.end
    FiscalDateTime(2017, 9, 30, 23, 59, 59)
 
+You can also get the current ``FiscalYear`` with:
+
+.. code-block:: python
+
+   >>> FiscalYear.current()
+   FiscalYear(2018)
 
 FiscalQuarter
 -------------
@@ -61,6 +66,12 @@ These objects represent the standalone ``FiscalQuarter`` class.
    >>> b in a
    True
 
+You can also get the current ``FiscalQuarter`` with:
+
+.. code-block:: python
+
+   >>> FiscalQuarter.current()
+   FiscalQuarter(2018, 2)
 
 FiscalDateTime
 --------------
diff --git a/docs/basic_usage.rst b/docs/basic_usage.rst
index 93a741c..a8730d7 100644
--- a/docs/basic_usage.rst
+++ b/docs/basic_usage.rst
@@ -17,6 +17,14 @@ The ``FiscalYear`` class provides an object for storing information about the st
    >>> a.end
    FiscalDateTime(2017, 9, 30, 23, 59, 59)
 
+You can also get the current ``FiscalYear`` with:
+
+.. code-block:: python
+
+   >>> from fiscalyear import *
+   >>> FiscalYear.current()
+   FiscalYear(2018)
+
 
 FiscalQuarter
 -------------
@@ -45,6 +53,14 @@ These objects represent the standalone ``FiscalQuarter`` class.
    >>> b in a
    True
 
+You can also get the current ``FiscalQuarter`` with:
+
+.. code-block:: python
+
+   >>> from fiscalyear import *
+   >>> FiscalQuarter.current()
+   FiscalQuarter(2018, 2)
+
 
 FiscalDateTime
 --------------
diff --git a/fiscalyear.py b/fiscalyear.py
index c6f8ddc..6802471 100644
--- a/fiscalyear.py
+++ b/fiscalyear.py
@@ -191,6 +191,16 @@ class FiscalYear(object):
         self._fiscal_year = fiscal_year
         return self
 
+    @classmethod
+    def current(cls):
+        """Alternative constructor. Returns the current FiscalYear.
+
+        :returns: A newly constructed FiscalYear object
+        :rtype: FiscalYear
+        """
+        today = FiscalDate.today()
+        return cls(today.fiscal_year)
+
     def __repr__(self):
         """Convert to formal string, for repr().
 
@@ -371,6 +381,16 @@ class FiscalQuarter(object):
         self._quarter = quarter
         return self
 
+    @classmethod
+    def current(cls):
+        """Alternative constructor. Returns the current FiscalQuarter.
+
+        :returns: A newly constructed FiscalQuarter object
+        :rtype: FiscalQuarter
+        """
+        today = FiscalDate.today()
+        return cls(today.fiscal_year, today.quarter)
+
     def __repr__(self):
         """Convert to formal string, for repr().
 
diff --git a/requirements.txt b/requirements.txt
index fe65f2d..228f95a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,7 @@
 codecov
 pytest
 pytest-cov
+pytest-mock
 pytest-runner
 sphinx
 sphinx_rtd_theme
diff --git a/setup.cfg b/setup.cfg
index d928416..4bca33d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -4,6 +4,3 @@ test=pytest
 [build_sphinx]
 source-dir=docs
 build-dir=docs/_build
-
-[metadata]
-license-file = LICENSE
diff --git a/setup.py b/setup.py
index 05153b5..e8225cd 100755
--- a/setup.py
+++ b/setup.py
@@ -42,8 +42,6 @@ setuptools.setup(
         'Programming Language :: Python :: 3.4',
         'Programming Language :: Python :: 3.5',
         'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
 
         # Type of package
         'Topic :: Office/Business :: Financial :: Accounting',
@@ -52,5 +50,5 @@ setuptools.setup(
     keywords=['fiscal year', 'fiscal quarter', 'calendar', 'datetime'],
     py_modules=[fiscalyear.__name__],
     setup_requires=['pytest-runner'],
-    tests_require=['pytest'],
+    tests_require=['pytest', 'pytest-mock'],
 )


Test patch:
diff --git a/docs/testing.rst b/docs/testing.rst
index 7a0c8c6..b9a21b0 100644
--- a/docs/testing.rst
+++ b/docs/testing.rst
@@ -1,8 +1,13 @@
 Testing
 =======
 
-``fiscalyear`` comes with a full test-suite called ``test_fiscalyear``. To run the test-suite, you will need to install the `pytest <https://docs.pytest.org/en/latest/>`_ package.
+``fiscalyear`` comes with a full test-suite called ``test_fiscalyear``. To run the test-suite, you
+will need to install the following packages:
 
+* `pytest <https://docs.pytest.org/en/latest/>`_
+* `pytest-cov <https://docs.pytest.org/en/latest/>`_
+* `pytest-mock <https://docs.pytest.org/en/latest/>`_
+* `pytest-runner <https://docs.pytest.org/en/latest/>`_
 
 Running tests
 -------------
diff --git a/test_fiscalyear.py b/test_fiscalyear.py
index 690835f..6a7a22c 100644
--- a/test_fiscalyear.py
+++ b/test_fiscalyear.py
@@ -125,6 +125,12 @@ class TestFiscalYear:
     def test_basic(self, a):
         assert a.fiscal_year == 2016
 
+    def test_current(self, mocker):
+        mock_today = mocker.patch.object(fiscalyear.FiscalDate, 'today')
+        mock_today.return_value =  fiscalyear.FiscalDate(2016, 10, 1)
+        current = fiscalyear.FiscalYear.current()
+        assert current == fiscalyear.FiscalYear(2017)
+
     def test_repr(self, a):
         assert repr(a) == 'FiscalYear(2016)'
 
@@ -268,6 +274,12 @@ class TestFiscalQuarter:
         assert a.fiscal_year == 2016
         assert a.quarter == 4
 
+    def test_current(self, mocker):
+        mock_today = mocker.patch.object(fiscalyear.FiscalDate, 'today')
+        mock_today.return_value =  fiscalyear.FiscalDate(2016, 10, 1)
+        current = fiscalyear.FiscalQuarter.current()
+        assert current == fiscalyear.FiscalQuarter(2017, 1)
+
     def test_repr(self, a):
         assert repr(a) == 'FiscalQuarter(2016, 4)'