Skip to content

Commit

Permalink
Merge pull request #62 from statisticsnorway/20241009formatfiks
Browse files Browse the repository at this point in the history
20241009formatfiks
  • Loading branch information
joxssb authored Oct 9, 2024
2 parents 646d786 + f991d91 commit eaa9475
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/ssb_konjunk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ssb\_konjunk.xml\_handling module
:members:
:undoc-members:
:show-inheritance:

ssb\_konjunk.rounding module
---------------------------------

Expand Down
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.11"
version = "0.1.12"
description = "SSB Konjunk"
authors = ["Edvard Garmannslund <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 5 additions & 0 deletions src/ssb_konjunk/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
28 changes: 16 additions & 12 deletions tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit eaa9475

Please sign in to comment.