From 1a0a951b06c1da77bf61e498d501b488b328b506 Mon Sep 17 00:00:00 2001 From: bclodius Date: Sat, 5 May 2018 15:22:29 -0400 Subject: [PATCH] Fixes #1608 --- moto/cloudwatch/models.py | 7 ++++++- moto/cloudwatch/responses.py | 2 +- tests/test_cloudwatch/test_cloudwatch_boto3.py | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/moto/cloudwatch/models.py b/moto/cloudwatch/models.py index ba6569981..441c74176 100644 --- a/moto/cloudwatch/models.py +++ b/moto/cloudwatch/models.py @@ -229,8 +229,13 @@ class CloudWatchBackend(BaseBackend): def put_metric_data(self, namespace, metric_data): for metric_member in metric_data: + # Preserve "datetime" for get_metric_statistics comparisons + timestamp = metric_member.get('Timestamp') + if timestamp is not None and type(timestamp) != datetime: + timestamp = datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ') + timestamp = timestamp.replace(tzinfo=tzutc()) self.metric_data.append(MetricDatum( - namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member.get('Dimensions.member', _EMPTY_LIST), metric_member.get('Timestamp'))) + namespace, metric_member['MetricName'], float(metric_member['Value']), metric_member.get('Dimensions.member', _EMPTY_LIST), timestamp)) def get_metric_statistics(self, namespace, metric_name, start_time, end_time, period, stats): period_delta = timedelta(seconds=period) diff --git a/moto/cloudwatch/responses.py b/moto/cloudwatch/responses.py index c080d4620..8118f35ba 100644 --- a/moto/cloudwatch/responses.py +++ b/moto/cloudwatch/responses.py @@ -272,7 +272,7 @@ GET_METRIC_STATISTICS_TEMPLATE = """