diff --git a/.gitignore b/.gitignore index 495bb5e..2c7d033 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,11 @@ *.xlsx *.zip +# Notebooks shall be stored in .py or .R-format. +# See https://adr.ssb.no/0020-lagringsformat-for-jupyter-notebooks/ +*.ipynb + + # The section below is from the GitHub .gitignore template for Python: # https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore @@ -204,18 +209,7 @@ rsconnect/ # ignore poetry in .config .poetry/** -/.python-version -/.pytype/ -/docs/_build/ - -# Visual Studio Code -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets -# Local History for Visual Studio Code -.history/ -# Built Visual Studio Code Extensions -*.vsix + +# Blaise specific ignores +*.bdix +*.bdbx diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index 1d72a88..0ecbe8e 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -49,3 +49,11 @@ ssb\_konjunk.xml\_handling module :members: :undoc-members: :show-inheritance: + +ssb\_konjunk.rounding module +--------------------------------- + +.. automodule:: ssb_konjunk.rounding + :members: + :undoc-members: + :show-inheritance: diff --git a/poetry.lock b/poetry.lock index 65a8049..d91fda0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" @@ -3168,6 +3168,7 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, diff --git a/pyproject.toml b/pyproject.toml index 9cc4f0e..43f9231 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ssb-konjunk" -version = "0.1.9" +version = "0.1.10" description = "SSB Konjunk" authors = ["Edvard Garmannslund "] license = "MIT" diff --git a/src/ssb_konjunk/timestamp.py b/src/ssb_konjunk/timestamp.py index 3e826eb..2b6a5b7 100644 --- a/src/ssb_konjunk/timestamp.py +++ b/src/ssb_konjunk/timestamp.py @@ -263,3 +263,26 @@ def get_ssb_timestamp(*args: int, frequency: str = "M") -> str | None: return _get_timestamp_yearly(*valid_args) else: return _get_timestamp_special(*valid_args, frequency=frequency) + + +def check_periodic_year(year: int, cycle_year: int, period: int) -> bool: + """Check if a year is a part of a periodic cycle. + + An example of use: a functionality should be performed every third + year, starting in year 2021. I.e. not in 2022 and 2023, but in + 2024. Then this function should return True when passing + 2024 as the year argument, 2021 (or 2015, 2018, 2024 and so) is + passed as the cycle year and period is passed as 3 (triennal period). + + Args: + year: the year to check. + cycle_year: a year in the cycle. + period: the number of years in a period. + + Returns: + bool: whether or not the year is part of the triennal cycle. + """ + if abs(year - cycle_year) % period == 0: + return True + else: + return False diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py index 1d6dc76..7d6ae9d 100644 --- a/tests/test_timestamp.py +++ b/tests/test_timestamp.py @@ -14,6 +14,7 @@ from ssb_konjunk.timestamp import _get_timestamp_daily from ssb_konjunk.timestamp import _get_timestamp_special from ssb_konjunk.timestamp import _get_timestamp_yearly +from ssb_konjunk.timestamp import check_periodic_year from ssb_konjunk.timestamp import get_ssb_timestamp @@ -173,3 +174,12 @@ def test_check_valid_year() -> None: match=f"The order of args is start date and then end date. Therefore first year arg can not be bigger than the last. Your args are start year:{year1} end year:{year2}.", ): _check_valid_year(year1, year2) + + +def test_check_periodic_year() -> None: + """Test of function check_periodic_year.""" + assert check_periodic_year(2024, 2021, 3) + assert not check_periodic_year(2024, 2021, 2) + assert check_periodic_year(2021, 2024, 3) + assert check_periodic_year(2021, 2021, 3) + assert check_periodic_year(2021, 2022, 1)