langchain[patch]: fix a bug where now.replace(day=now.day - 1) would raise a ValueError when now.day is equal to 1 (#31878)

This commit is contained in:
NeatGuyCoding 2025-07-06 02:54:26 +08:00 committed by GitHub
parent 15dc684d34
commit 64815445e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
from datetime import datetime from datetime import datetime, timedelta
from langchain_core.exceptions import OutputParserException from langchain_core.exceptions import OutputParserException
from langchain_core.output_parsers import BaseOutputParser from langchain_core.output_parsers import BaseOutputParser
@ -31,7 +31,7 @@ class DatetimeOutputParser(BaseOutputParser[datetime]):
[ [
now.strftime(self.format), now.strftime(self.format),
(now.replace(year=now.year - 1)).strftime(self.format), (now.replace(year=now.year - 1)).strftime(self.format),
(now.replace(day=now.day - 1)).strftime(self.format), (now - timedelta(days=1)).strftime(self.format),
] ]
) )
except ValueError: except ValueError: