Skip to content

Commit 73dea54

Browse files
committed
[python] Remove pattern matching operators to be compatible with older python versions
1 parent 54804b2 commit 73dea54

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

dates_calc.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ depends: [
2222
"ocaml" {>= "4.11.0"}
2323
"alcotest" {with-test & >= "1.0.0"}
2424
"qcheck" {with-test & >= "0.10"}
25-
# "conf-python" {with-test}, actually, python>=3.12 is needed for the tests. Cf. https://github.com/ocaml/opam-repository/pull/26738
25+
"conf-python-3" {with-test}
2626
"conf-openjdk" {with-test}
2727
"odoc" {with-doc}
2828
]

lib_python/src/dates_calc/dates.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ def is_leap_year(year : int) -> bool:
4040
return (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)
4141

4242
def days_in_month(*, month : int, is_leap_year : bool) -> int:
43-
match month:
44-
case 1 | 3 | 5 | 7 | 8 | 10 | 12: return 31
45-
case 4 | 6 | 9 | 11: return 30
46-
case 2:
47-
return 29 if is_leap_year else 28
48-
case _:
49-
raise InvalidDate
43+
if month in [1, 3, 5, 7, 8, 10, 12]: return 31
44+
elif month in [4, 6, 9, 11]: return 30
45+
elif month == 2:
46+
return 29 if is_leap_year else 28
47+
else:
48+
raise InvalidDate
5049

5150
def add_months_to_first_of_month_date(*, year : int, month : int, months : int) -> tuple[int, int]:
5251
"""
@@ -139,10 +138,9 @@ def last_day_of_month(self) -> Date:
139138
def round(self, round : DateRounding) -> Date:
140139
if self.is_valid: return self
141140
else:
142-
match round:
143-
case DateRounding.AbortOnRound: raise AmbiguousComputation
144-
case DateRounding.RoundDown: return self.prev_valid_date()
145-
case DateRounding.RoundUp: return self.next_valid_date()
141+
if round == DateRounding.AbortOnRound: raise AmbiguousComputation
142+
elif round == DateRounding.RoundDown: return self.prev_valid_date()
143+
elif round == DateRounding.RoundUp: return self.next_valid_date()
146144

147145
# This function is only ever called from `add_dates` below.
148146
# Hence, any call to `add_dates_years` will be followed by a call

0 commit comments

Comments
 (0)