1515
1616import json
1717import pprint
18+ import re # noqa: F401
1819from datetime import datetime
1920from typing import Any , ClassVar , Dict , List , Optional , Set
2021
21- from pydantic import BaseModel , ConfigDict
22+ from pydantic import BaseModel , ConfigDict , field_validator
2223from typing_extensions import Self
2324
2425
@@ -31,6 +32,32 @@ class TimeWindow(BaseModel):
3132 start : datetime
3233 __properties : ClassVar [List [str ]] = ["end" , "start" ]
3334
35+ @field_validator ("end" , mode = "before" )
36+ def end_change_year_zero_to_one (cls , value ):
37+ """Workaround which prevents year 0 issue"""
38+ if isinstance (value , str ):
39+ # Check for year "0000" at the beginning of the string
40+ # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
41+ if value .startswith ("0000-01-01T" ) and re .match (
42+ r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$" , value
43+ ):
44+ # Workaround: Replace "0000" with "0001"
45+ return "0001" + value [4 :] # Take "0001" and append the rest of the string
46+ return value
47+
48+ @field_validator ("start" , mode = "before" )
49+ def start_change_year_zero_to_one (cls , value ):
50+ """Workaround which prevents year 0 issue"""
51+ if isinstance (value , str ):
52+ # Check for year "0000" at the beginning of the string
53+ # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ
54+ if value .startswith ("0000-01-01T" ) and re .match (
55+ r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$" , value
56+ ):
57+ # Workaround: Replace "0000" with "0001"
58+ return "0001" + value [4 :] # Take "0001" and append the rest of the string
59+ return value
60+
3461 model_config = ConfigDict (
3562 populate_by_name = True ,
3663 validate_assignment = True ,
0 commit comments