|
16 | 16 |
|
17 | 17 | import json |
18 | 18 | import pprint |
| 19 | +import re # noqa: F401 |
19 | 20 | from datetime import datetime |
20 | 21 | from typing import Any, ClassVar, Dict, List, Optional, Set |
21 | 22 |
|
22 | | -from pydantic import BaseModel, ConfigDict, Field, StrictStr |
| 23 | +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator |
23 | 24 | from typing_extensions import Self |
24 | 25 |
|
25 | 26 | from stackit.scf.models.quota_apps import QuotaApps |
@@ -60,6 +61,32 @@ class Quota(BaseModel): |
60 | 61 | "updatedAt", |
61 | 62 | ] |
62 | 63 |
|
| 64 | + @field_validator("created_at", mode="before") |
| 65 | + def created_at_change_year_zero_to_one(cls, value): |
| 66 | + """Workaround which prevents year 0 issue""" |
| 67 | + if isinstance(value, str): |
| 68 | + # Check for year "0000" at the beginning of the string |
| 69 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 70 | + if value.startswith("0000-01-01T") and re.match( |
| 71 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 72 | + ): |
| 73 | + # Workaround: Replace "0000" with "0001" |
| 74 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 75 | + return value |
| 76 | + |
| 77 | + @field_validator("updated_at", mode="before") |
| 78 | + def updated_at_change_year_zero_to_one(cls, value): |
| 79 | + """Workaround which prevents year 0 issue""" |
| 80 | + if isinstance(value, str): |
| 81 | + # Check for year "0000" at the beginning of the string |
| 82 | + # This assumes common date formats like YYYY-MM-DDTHH:MM:SS+00:00 or YYYY-MM-DDTHH:MM:SSZ |
| 83 | + if value.startswith("0000-01-01T") and re.match( |
| 84 | + r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+\d{2}:\d{2}|Z)$", value |
| 85 | + ): |
| 86 | + # Workaround: Replace "0000" with "0001" |
| 87 | + return "0001" + value[4:] # Take "0001" and append the rest of the string |
| 88 | + return value |
| 89 | + |
63 | 90 | model_config = ConfigDict( |
64 | 91 | populate_by_name=True, |
65 | 92 | validate_assignment=True, |
|
0 commit comments