|
1 | 1 | from dataclasses import dataclass, field, fields, is_dataclass |
2 | | -from datetime import datetime, timezone |
| 2 | +from datetime import datetime |
3 | 3 | from enum import Enum |
4 | 4 |
|
5 | 5 | from .utils import update_dataclass_from_dict |
|
9 | 9 | MetadataConfig, |
10 | 10 | ResourceConfigTemplate, |
11 | 11 | ) |
| 12 | +from ..utils.helper_functions import datetime_to_string |
12 | 13 | from .top_level.utils import InlineList |
13 | 14 | from .top_level.providers import ProviderTemplate |
14 | 15 | from .top_level.providers.records import ProviderTypes |
@@ -141,14 +142,6 @@ def all_missing_props(self): |
141 | 142 | return self._all_missing_props |
142 | 143 | return [] |
143 | 144 |
|
144 | | - def datetime_to_string(self, data: datetime): |
145 | | - # normalize to UTC and format with Z |
146 | | - if data.tzinfo is None: |
147 | | - data = data.replace(tzinfo=timezone.utc) |
148 | | - else: |
149 | | - data = data.astimezone(timezone.utc) |
150 | | - return data.strftime("%Y-%m-%dT%H:%M:%SZ") |
151 | | - |
152 | 145 | def asdict_enum_safe(self, obj, datetime_to_str=False): |
153 | 146 | """Overwriting dataclass 'asdict' fuction to replace Enums with strings.""" |
154 | 147 | if is_dataclass(obj): |
@@ -177,7 +170,7 @@ def asdict_enum_safe(self, obj, datetime_to_str=False): |
177 | 170 | } |
178 | 171 | else: |
179 | 172 | if isinstance(obj, datetime) and datetime_to_str: |
180 | | - return self.datetime_to_string(obj) |
| 173 | + return datetime_to_string(obj) |
181 | 174 | else: |
182 | 175 | return obj |
183 | 176 |
|
|
0 commit comments