Skip to content

Commit 40fd881

Browse files
bivalddaspecster
authored andcommitted
Add storage.blob property time_created (timeCreated) (#2933)
Add storage.blob property time_created (timeCreated) (#2933)
1 parent 87879d0 commit 40fd881

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

storage/google/cloud/storage/blob.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,20 @@ def time_deleted(self):
932932
if value is not None:
933933
return _rfc3339_to_datetime(value)
934934

935+
@property
936+
def time_created(self):
937+
"""Retrieve the timestamp at which the object was created.
938+
939+
See: https://cloud.google.com/storage/docs/json_api/v1/objects
940+
941+
:rtype: :class:`datetime.datetime` or ``NoneType``
942+
:returns: Datetime object parsed from RFC3339 valid timestamp, or
943+
``None`` if the property is not set locally.
944+
"""
945+
value = self._properties.get('timeCreated')
946+
if value is not None:
947+
return _rfc3339_to_datetime(value)
948+
935949
@property
936950
def updated(self):
937951
"""Retrieve the timestamp at which the object was updated.

storage/unit_tests/test_blob.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,23 @@ def test_time_deleted_unset(self):
16441644
blob = self._make_one('blob-name', bucket=BUCKET)
16451645
self.assertIsNone(blob.time_deleted)
16461646

1647+
def test_time_created(self):
1648+
import datetime
1649+
from google.cloud._helpers import _RFC3339_MICROS
1650+
from google.cloud._helpers import UTC
1651+
BLOB_NAME = 'blob-name'
1652+
bucket = _Bucket()
1653+
TIMESTAMP = datetime.datetime(2014, 11, 5, 20, 34, 37, tzinfo=UTC)
1654+
TIME_CREATED = TIMESTAMP.strftime(_RFC3339_MICROS)
1655+
properties = {'timeCreated': TIME_CREATED}
1656+
blob = self._make_one(BLOB_NAME, bucket=bucket, properties=properties)
1657+
self.assertEqual(blob.time_created, TIMESTAMP)
1658+
1659+
def test_time_created_unset(self):
1660+
BUCKET = object()
1661+
blob = self._make_one('blob-name', bucket=BUCKET)
1662+
self.assertIsNone(blob.time_created)
1663+
16471664
def test_updated(self):
16481665
import datetime
16491666
from google.cloud._helpers import _RFC3339_MICROS

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy