diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index 649c439..2b31a3d 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -26,6 +26,14 @@ ssb\_konjunk.prompts module :undoc-members: :show-inheritance: +ssb\_konjunk.rounding module +---------------------------- + +.. automodule:: ssb_konjunk.rounding + :members: + :undoc-members: + :show-inheritance: + ssb\_konjunk.saving module -------------------------- @@ -34,26 +42,26 @@ ssb\_konjunk.saving module :undoc-members: :show-inheritance: -ssb\_konjunk.timestamp module ------------------------------ +ssb\_konjunk.statbank\_format module +------------------------------------ -.. automodule:: ssb_konjunk.timestamp +.. automodule:: ssb_konjunk.statbank_format :members: :undoc-members: :show-inheritance: -ssb\_konjunk.xml\_handling module ---------------------------------- +ssb\_konjunk.timestamp module +----------------------------- -.. automodule:: ssb_konjunk.xml_handling +.. automodule:: ssb_konjunk.timestamp :members: :undoc-members: :show-inheritance: -ssb\_konjunk.rounding module +ssb\_konjunk.xml\_handling module --------------------------------- -.. automodule:: ssb_konjunk.rounding +.. automodule:: ssb_konjunk.xml_handling :members: :undoc-members: :show-inheritance: diff --git a/pyproject.toml b/pyproject.toml index 162a5aa..3edc922 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ssb-konjunk" -version = "0.1.13" +version = "0.1.14" description = "SSB Konjunk" authors = ["Edvard Garmannslund "] license = "MIT" diff --git a/src/ssb_konjunk/prompts.py b/src/ssb_konjunk/prompts.py index 27dc0f9..1bfaa7e 100644 --- a/src/ssb_konjunk/prompts.py +++ b/src/ssb_konjunk/prompts.py @@ -335,3 +335,24 @@ def publishing_date() -> str: date = set_publishing_date() ok_date = check_publishing_date(date) return ok_date + + +def get_previous_month(year: str | int, month: str | int) -> list[int]: + """Turn e.g. month 01 year 2023 into month 12 and year 2022. + + Args: + year: the current year YYYY. + month: the current month MM. + + Returns: + list[int]: the previous month with year. + """ + prev_month = int(month) - 1 + + if prev_month != 0: + prev_year = int(year) + else: + prev_month = 12 + prev_year = int(year) - 1 + + return [prev_year, prev_month] diff --git a/tests/test_prompts.py b/tests/test_prompts.py index a096bb2..9ba2f42 100644 --- a/tests/test_prompts.py +++ b/tests/test_prompts.py @@ -5,6 +5,7 @@ from ssb_konjunk.prompts import bump_quarter from ssb_konjunk.prompts import days_in_month from ssb_konjunk.prompts import extract_start_end_dates +from ssb_konjunk.prompts import get_previous_month from ssb_konjunk.prompts import iterate_years_months from ssb_konjunk.prompts import validate_month @@ -148,3 +149,13 @@ def test_validate_month() -> None: assert validate_month(10) == "10" assert validate_month("10") == "10" + + +def test_get_previous_month() -> None: + prev_month = get_previous_month(2022, 1) + assert prev_month[0] == 2021, f"Previous year for previous month: {prev_month[0]}" + assert prev_month[1] == 12, f"Previous month for previous month: {prev_month[1]}" + + prev_month = get_previous_month(2022, 12) + assert prev_month[0] == 2022, f"Previous year for previous month: {prev_month[0]}" + assert prev_month[1] == 11, f"Previous month for previous month: {prev_month[1]}"