Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

This comment was marked as spam.

@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