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 prev period #64

Merged
merged 11 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions docs/ssb_konjunk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------

Expand All @@ -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:
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-konjunk"
version = "0.1.13"
version = "0.1.14"
description = "SSB Konjunk"
authors = ["Edvard Garmannslund <[email protected]>"]
license = "MIT"
Expand Down
21 changes: 21 additions & 0 deletions src/ssb_konjunk/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
11 changes: 11 additions & 0 deletions tests/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]}"