Skip to content

Commit

Permalink
Add storage.blob property time_created (timeCreated) (googleapis#2933)
Browse files Browse the repository at this point in the history
Add storage.blob property time_created (timeCreated) (googleapis#2933)
  • Loading branch information
bivald authored and daspecster committed Jan 13, 2017
1 parent 0c0a698 commit aa74955
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,20 @@ def time_deleted(self):
if value is not None:
return _rfc3339_to_datetime(value)

@property
def time_created(self):
"""Retrieve the timestamp at which the object was created.
See: https://cloud.google.com/storage/docs/json_api/v1/objects
:rtype: :class:`datetime.datetime` or ``NoneType``
:returns: Datetime object parsed from RFC3339 valid timestamp, or
``None`` if the property is not set locally.
"""
value = self._properties.get('timeCreated')
if value is not None:
return _rfc3339_to_datetime(value)

@property
def updated(self):
"""Retrieve the timestamp at which the object was updated.
Expand Down
17 changes: 17 additions & 0 deletions storage/unit_tests/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,23 @@ def test_time_deleted_unset(self):
blob = self._make_one('blob-name', bucket=BUCKET)
self.assertIsNone(blob.time_deleted)

def test_time_created(self):
import datetime
from google.cloud._helpers import _RFC3339_MICROS
from google.cloud._helpers import UTC
BLOB_NAME = 'blob-name'
bucket = _Bucket()
TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=UTC)
TIME_CREATED = TIMESTAMP.strftime(_RFC3339_MICROS)
properties = {'timeCreated': TIME_CREATED}
blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties)
self.assertEqual(blob.time_created, TIMESTAMP)

def test_time_created_unset(self):
BUCKET = object()
blob = self._make_one('blob-name', bucket=BUCKET)
self.assertIsNone(blob.time_created)

def test_updated(self):
import datetime
from google.cloud._helpers import _RFC3339_MICROS
Expand Down

0 comments on commit aa74955

Please sign in to comment.