diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6a78f..6186cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.3.2] - 2024-09-10 + +### Added + +- Fixed numeric strings from being parsed as Datetime objects to being parsed as strings. +-Only parse to Datetime objects that conform to ISO 8601 format. + + ## [1.3.1] - 2024-08-23 diff --git a/kiota_serialization_json/_version.py b/kiota_serialization_json/_version.py index d045b44..b84f08f 100644 --- a/kiota_serialization_json/_version.py +++ b/kiota_serialization_json/_version.py @@ -1 +1 @@ -VERSION: str = '1.3.1' +VERSION: str = '1.3.2' diff --git a/kiota_serialization_json/json_parse_node.py b/kiota_serialization_json/json_parse_node.py index ac3252e..937ccd3 100644 --- a/kiota_serialization_json/json_parse_node.py +++ b/kiota_serialization_json/json_parse_node.py @@ -293,10 +293,6 @@ def _assign_field_values(self, item: U) -> None: deserialize but the model doesn't support additional data" ) - def __is_four_digit_number(self, value: str) -> bool: - pattern = r'^\d{4}$' - return bool(re.match(pattern, value)) - def try_get_anything(self, value: Any) -> Any: if isinstance(value, (int, float, bool)) or value is None: return value @@ -306,9 +302,8 @@ def try_get_anything(self, value: Any) -> Any: return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items())) if isinstance(value, str): try: - if self.__is_four_digit_number(value): + if value.isdigit(): return value - datetime_obj = pendulum.parse(value) if isinstance(datetime_obj, pendulum.Duration): return datetime_obj.as_timedelta() diff --git a/tests/unit/test_json_parse_node.py b/tests/unit/test_json_parse_node.py index 7bec942..cf1e003 100644 --- a/tests/unit/test_json_parse_node.py +++ b/tests/unit/test_json_parse_node.py @@ -141,6 +141,25 @@ def test_get_anythin_does_not_convert_numeric_chars_to_datetime(): assert result == "1212" +def test_get_anythin_does_not_convert_any_length_numeric_chars_to_datetime(): + parse_node = JsonParseNode("1212") + result1 = parse_node.try_get_anything("1212") + parse_node_two = JsonParseNode("-PT15M") + result2 = parse_node_two.try_get_anything("-PT15M") + parse_node_three = JsonParseNode("20081008") + result3 = parse_node_three.try_get_anything("20081008") + parse_node_four = JsonParseNode("1011317") + result4 = parse_node_four.try_get_anything("1011317") + assert isinstance(result1, str) + assert result1 == "1212" + assert isinstance(result2, str) + assert result2 == "-PT15M" + assert isinstance(result3, str) + assert result3 == "20081008" + assert isinstance(result4, str) + assert result4 == "1011317" + + def test_get_anythin_does_convert_date_string_to_datetime(): parse_node = JsonParseNode("2023-10-05T14:48:00.000Z") result = parse_node.try_get_anything("2023-10-05T14:48:00.000Z")