fix: handle new description

This commit is contained in:
NateScarlet 2024-11-12 20:29:26 +08:00
parent aefd2f1458
commit a7a1065c70
No known key found for this signature in database
GPG Key ID: 5C242793B070309C
2 changed files with 10 additions and 2 deletions

View File

@ -1,4 +1,9 @@
[
{
"year": 2024,
"description": "1月1日周三放假1天不调休",
"expected": [{ "date": "2024-01-01", "isOffDay": true }]
},
{
"year": 2019,
"description": "2018年12月30日至2019年1月1日放假调休共3天。2018年12月29日星期六上班。",

View File

@ -277,7 +277,7 @@ class DescriptionParser:
class SentenceParser:
"""Parser for holiday shift description sentence."""
def __init__(self, parent: DescriptionParser, sentence):
def __init__(self, parent: DescriptionParser, sentence: str):
self.parent = parent
self.sentence = sentence
@ -316,7 +316,8 @@ class SentenceParser:
def _extract_dates_2(self, value: str) -> Iterator[date]:
value = re.sub(r".+?", "", value)
match = re.findall(
r"(?:(\d+)年)?(?:(\d+)月)?(\d+)日(?:至|-|—)(?:(\d+)年)?(?:(\d+)月)?(\d+)日", value
r"(?:(\d+)年)?(?:(\d+)月)?(\d+)日(?:至|-|—)(?:(\d+)年)?(?:(\d+)月)?(\d+)日",
value,
)
for groups in match:
groups = [_cast_int(i) for i in groups]
@ -357,6 +358,8 @@ class SentenceParser:
yield i
def _parse_rest_1(self):
if self.sentence.startswith(""):
return
match = re.match(r"(.+)(放假|补休|调休|公休)+(?:\d+天)?$", self.sentence)
if match:
for i in self.extract_dates(match.group(1)):