diff --git a/docs/ssb_konjunk.rst b/docs/ssb_konjunk.rst index 0ecbe8e..649c439 100644 --- a/docs/ssb_konjunk.rst +++ b/docs/ssb_konjunk.rst @@ -49,7 +49,7 @@ ssb\_konjunk.xml\_handling module :members: :undoc-members: :show-inheritance: - + ssb\_konjunk.rounding module --------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 2a7ed85..f801247 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ssb-konjunk" -version = "0.1.11" +version = "0.1.12" description = "SSB Konjunk" authors = ["Edvard Garmannslund "] license = "MIT" diff --git a/src/ssb_konjunk/timestamp.py b/src/ssb_konjunk/timestamp.py index 2b6a5b7..69a08a9 100644 --- a/src/ssb_konjunk/timestamp.py +++ b/src/ssb_konjunk/timestamp.py @@ -196,6 +196,8 @@ def _get_timestamp_special(*args: int, frequency: str) -> str | None: if frequency in ["M", "W"]: if frequency == "M": frequency = "-" + if frequency == "W": + frequency = "-W" if len(args) == 2: return f"p{args[0]}{frequency}{args[1]:02}" elif len(args) == 4: @@ -204,7 +206,10 @@ def _get_timestamp_special(*args: int, frequency: str) -> str | None: ) else: return None + else: + if frequency in ["Q", "B", "T", "H"]: + frequency = f"-{frequency}" if len(args) == 2: return f"p{args[0]}{frequency}{args[1]}" elif len(args) == 4: diff --git a/tests/test_timestamp.py b/tests/test_timestamp.py index 7d6ae9d..bd3db5d 100644 --- a/tests/test_timestamp.py +++ b/tests/test_timestamp.py @@ -45,31 +45,35 @@ def test_test_get_timestamp_special() -> None: _get_timestamp_special(2020, 1, 2021, 2, frequency="M") == "p2020-01_p2021-02" ) # Testing quarter - assert _get_timestamp_special(2020, 1, 2021, 2, frequency="Q") == "p2020Q1_p2021Q2" + assert ( + _get_timestamp_special(2020, 1, 2021, 2, frequency="Q") == "p2020-Q1_p2021-Q2" + ) # Testing term - assert _get_timestamp_special(2020, 1, 2021, 2, frequency="B") == "p2020B1_p2021B2" + assert ( + _get_timestamp_special(2020, 1, 2021, 2, frequency="B") == "p2020-B1_p2021-B2" + ) def test_get_ssb_timestamp() -> None: """Test of function get_ssb_timestamp.""" # Testing week - assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="W") == "p2020W01_p2021W02" - assert get_ssb_timestamp(2020, 1, frequency="W") == "p2020W01" + assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="W") == "p2020-W01_p2021-W02" + assert get_ssb_timestamp(2020, 1, frequency="W") == "p2020-W01" # Testing month assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="M") == "p2020-01_p2021-02" assert get_ssb_timestamp(2020, 1) == "p2020-01" # Testing quarter - assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="Q") == "p2020Q1_p2021Q2" - assert get_ssb_timestamp(2020, 1, frequency="Q") == "p2020Q1" + assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="Q") == "p2020-Q1_p2021-Q2" + assert get_ssb_timestamp(2020, 1, frequency="Q") == "p2020-Q1" # Testing term - assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="B") == "p2020B1_p2021B2" - assert get_ssb_timestamp(2020, 1, frequency="B") == "p2020B1" + assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="B") == "p2020-B1_p2021-B2" + assert get_ssb_timestamp(2020, 1, frequency="B") == "p2020-B1" # Testing trimester - assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="T") == "p2020T1_p2021T2" - assert get_ssb_timestamp(2020, 1, frequency="T") == "p2020T1" + assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="T") == "p2020-T1_p2021-T2" + assert get_ssb_timestamp(2020, 1, frequency="T") == "p2020-T1" # Testing half year - assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="H") == "p2020H1_p2021H2" - assert get_ssb_timestamp(2020, 1, frequency="H") == "p2020H1" + assert get_ssb_timestamp(2020, 1, 2021, 2, frequency="H") == "p2020-H1_p2021-H2" + assert get_ssb_timestamp(2020, 1, frequency="H") == "p2020-H1" # Testing day assert ( get_ssb_timestamp(2020, 1, 1, 2020, 1, 31, frequency="D")