Skip to content

Commit

Permalink
headache
Browse files Browse the repository at this point in the history
  • Loading branch information
majiidd committed Mar 24, 2024
1 parent 045a946 commit f3b6368
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions persiantools/jdatetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def strptime(cls, data_string, fmt, locale="en"):
"%B": cls.__seqToRE(cls, month_names, "B"),
"%H": r"(?P<H>2[0-3]|[0-1]\d|\d)",
"%I": r"(?P<I>1[0-2]|0[1-9]|[1-9])",
"%p": "(?i)" + cls.__seqToRE(cls, periods, "p"),
"%p": cls.__seqToRE(cls, periods, "p", "(?i)"),
"%M": r"(?P<M>[0-5]\d|\d)",
"%S": r"(?P<S>6[0-1]|[0-5]\d|\d)",
"%f": r"(?P<f>\d{1,6})",
Expand Down Expand Up @@ -1029,15 +1029,15 @@ def strptime(cls, data_string, fmt, locale="en"):
else:
raise ValueError("data string and format are not matched")

def __seqToRE(self, to_convert, directive):
def __seqToRE(self, to_convert, directive, flags=""):
to_convert = sorted(to_convert, key=len, reverse=True)
for value in to_convert:
if value != "":
break
else:
return ""
regex = "|".join(re_escape(stuff) for stuff in to_convert)
regex = f"(?P<{directive}>{regex}"
regex = f"{flags}(?P<{directive}>{regex}"
return "%s)" % regex

def __repr__(self):
Expand Down

0 comments on commit f3b6368

Please sign in to comment.