diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py index 4eadff89aa2f..2926ec2992f6 100644 --- a/gcloud/storage/blob.py +++ b/gcloud/storage/blob.py @@ -22,6 +22,7 @@ import os import time +import pytz import six from six.moves.urllib.parse import quote # pylint: disable=F0401 @@ -749,7 +750,8 @@ def time_deleted(self): """ value = self._properties.get('timeDeleted') if value is not None: - return datetime.datetime.strptime(value, _RFC3339_MICROS) + naive = datetime.datetime.strptime(value, _RFC3339_MICROS) + return naive.replace(tzinfo=pytz.utc) @property def updated(self): @@ -763,7 +765,8 @@ def updated(self): """ value = self._properties.get('updated') if value is not None: - return datetime.datetime.strptime(value, _RFC3339_MICROS) + naive = datetime.datetime.strptime(value, _RFC3339_MICROS) + return naive.replace(tzinfo=pytz.utc) class _UploadConfig(object): diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index d4ae8bb5a044..d45383b19ffc 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -36,6 +36,8 @@ import datetime import copy import os + +import pytz import six from gcloud._helpers import get_default_project @@ -693,7 +695,8 @@ def time_created(self): """ value = self._properties.get('timeCreated') if value is not None: - return datetime.datetime.strptime(value, _RFC3339_MICROS) + naive = datetime.datetime.strptime(value, _RFC3339_MICROS) + return naive.replace(tzinfo=pytz.utc) @property def versioning_enabled(self): diff --git a/gcloud/storage/test_blob.py b/gcloud/storage/test_blob.py index 08bbbdc77117..07791862ba53 100644 --- a/gcloud/storage/test_blob.py +++ b/gcloud/storage/test_blob.py @@ -1016,11 +1016,12 @@ def test_storage_class(self): def test_time_deleted(self): import datetime + from pytz import utc from gcloud._helpers import _RFC3339_MICROS BLOB_NAME = 'blob-name' connection = _Connection() bucket = _Bucket(connection) - TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37) + TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=utc) TIME_DELETED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'timeDeleted': TIME_DELETED} blob = self._makeOne(BLOB_NAME, bucket=bucket, properties=properties) @@ -1033,11 +1034,12 @@ def test_time_deleted_unset(self): def test_updated(self): import datetime + from pytz import utc from gcloud._helpers import _RFC3339_MICROS BLOB_NAME = 'blob-name' connection = _Connection() bucket = _Bucket(connection) - TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37) + TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=utc) UPDATED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'updated': UPDATED} blob = self._makeOne(BLOB_NAME, bucket=bucket, properties=properties) diff --git a/gcloud/storage/test_bucket.py b/gcloud/storage/test_bucket.py index 43273aafc955..c9ae0e56b320 100644 --- a/gcloud/storage/test_bucket.py +++ b/gcloud/storage/test_bucket.py @@ -790,8 +790,9 @@ def test_storage_class(self): def test_time_created(self): import datetime + from pytz import utc from gcloud._helpers import _RFC3339_MICROS - TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37) + TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=utc) TIME_CREATED = TIMESTAMP.strftime(_RFC3339_MICROS) properties = {'timeCreated': TIME_CREATED} bucket = self._makeOne(properties=properties)