ssb-konjunk 0.1.16__tar.gz → 0.1.17__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ssb-konjunk
3
- Version: 0.1.16
3
+ Version: 0.1.17
4
4
  Summary: SSB Konjunk
5
5
  Home-page: https://github.com/statisticsnorway/ssb-konjunk
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ssb-konjunk"
3
- version = "0.1.16"
3
+ version = "0.1.17"
4
4
  description = "SSB Konjunk"
5
5
  authors = ["Edvard Garmannslund <ged@ssb.no>"]
6
6
  license = "MIT"
@@ -271,6 +271,59 @@ def validate_day(day: int | str) -> str:
271
271
  day = "0" + str(int(day))
272
272
  return str(day)
273
273
 
274
+
275
+ def quarter_for_month(month: str | int) -> int:
276
+ """Find corresponding quarter for a month.
277
+
278
+ Args:
279
+ month: Month to find corresponding quarter for.
280
+
281
+ Returns:
282
+ int: The corresponding quarter.
283
+
284
+ Raises:
285
+ ValueError: If invalid month
286
+ """
287
+ month = int(month)
288
+
289
+ if month < 1 or month > 12:
290
+ raise ValueError(f"Invalid month: {month}")
291
+
292
+ if month < 4:
293
+ return 1
294
+ elif month < 7:
295
+ return 2
296
+ elif month < 10:
297
+ return 3
298
+ else:
299
+ return 4
300
+
301
+
302
+ def months_in_quarter(quarter: int | str) -> list[int]:
303
+ """Return the three months in the quarter.
304
+
305
+ Args:
306
+ quarter: the relevant quarter.
307
+
308
+ Returns:
309
+ list: a list with the months in the quarter.
310
+
311
+ Raises:
312
+ ValueError: If invalid quarter.
313
+ """
314
+ quarter = int(quarter)
315
+
316
+ if quarter < 1 or quarter > 4:
317
+ raise ValueError(f"Invalid quarter: {quarter}")
318
+
319
+ if quarter == 1:
320
+ return [1, 2, 3]
321
+ elif quarter == 2:
322
+ return [4, 5, 6]
323
+ elif quarter == 3:
324
+ return [7, 8, 9]
325
+ else:
326
+ return [10, 11, 12]
274
327
 
275
328
  def set_publishing_date() -> str:
276
329
  """Set the date for publication of tables.
@@ -355,4 +408,4 @@ def get_previous_month(year: str | int, month: str | int) -> list[int]:
355
408
  prev_month = 12
356
409
  prev_year = int(year) - 1
357
410
 
358
- return [prev_year, prev_month]
411
+ return [prev_year, prev_month]
File without changes
File without changes