diff --git a/google/cloud/storage/bucket.py b/google/cloud/storage/bucket.py index 215e9ea20..caa3ddd57 100644 --- a/google/cloud/storage/bucket.py +++ b/google/cloud/storage/bucket.py @@ -2618,6 +2618,21 @@ def time_created(self): if value is not None: return _rfc3339_nanos_to_datetime(value) + @property + def updated(self): + """Retrieve the timestamp at which the bucket was last updated. + + See https://cloud.google.com/storage/docs/json_api/v1/buckets + + :rtype: :class:`datetime.datetime` or ``NoneType`` + :returns: Datetime object parsed from RFC3339 valid timestamp, or + ``None`` if the bucket's resource has not been loaded + from the server. + """ + value = self._properties.get("updated") + if value is not None: + return _rfc3339_nanos_to_datetime(value) + @property def versioning_enabled(self): """Is versioning enabled for this bucket? diff --git a/tests/unit/test_bucket.py b/tests/unit/test_bucket.py index 6a0e5e285..a5d276391 100644 --- a/tests/unit/test_bucket.py +++ b/tests/unit/test_bucket.py @@ -2959,6 +2959,19 @@ def test_time_created_unset(self): bucket = self._make_one() self.assertIsNone(bucket.time_created) + def test_updated(self): + from google.cloud._helpers import _RFC3339_MICROS + + TIMESTAMP = datetime.datetime(2023, 11, 5, 20, 34, 37, tzinfo=_UTC) + UPDATED = TIMESTAMP.strftime(_RFC3339_MICROS) + properties = {"updated": UPDATED} + bucket = self._make_one(properties=properties) + self.assertEqual(bucket.updated, TIMESTAMP) + + def test_updated_unset(self): + bucket = self._make_one() + self.assertIsNone(bucket.updated) + def test_versioning_enabled_getter_missing(self): NAME = "name" bucket = self._make_one(name=NAME)