Skip to content

Commit

Permalink
Merge pull request #64 from statisticsnorway/add_prev_period
Browse files Browse the repository at this point in the history
Add prev period
  • Loading branch information
joxssb authored Oct 22, 2024
2 parents 6e0bb64 + 5c87221 commit 8f92e6d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
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]}"

0 comments on commit 8f92e6d

Please sign in to comment.