Repository: googleapis/google-cloud-python

Issue:
BigQuery: Add creationTime and expirationTime properties to TableListItem
API reference: https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/list

The properties `creationTime` and `expirationTime` now appear in the API results for `list_tables()`. The `creationTime` properties is exposed as `Table.created`. A similar property needs to appear on `TableListItem`.

https://github.com/GoogleCloudPlatform/google-cloud-python/blob/62740078538ea84167705c15bf109c1a2737c648/bigquery/google/cloud/bigquery/table.py#L387-L397

Likewise `Table.expires` needs a corresponding property.

https://github.com/GoogleCloudPlatform/google-cloud-python/blob/62740078538ea84167705c15bf109c1a2737c648/bigquery/google/cloud/bigquery/table.py#L546-L556


Discussion:
/cc @lbristol88

Resolving patch:
diff --git a/bigquery/google/cloud/bigquery/table.py b/bigquery/google/cloud/bigquery/table.py
--- a/bigquery/google/cloud/bigquery/table.py
+++ b/bigquery/google/cloud/bigquery/table.py
@@ -906,6 +906,30 @@ def __init__(self, resource):
 
         self._properties = resource
 
+    @property
+    def created(self):
+        """Union[datetime.datetime, None]: Datetime at which the table was
+        created (:data:`None` until set from the server).
+        """
+        creation_time = self._properties.get("creationTime")
+        if creation_time is not None:
+            # creation_time will be in milliseconds.
+            return google.cloud._helpers._datetime_from_microseconds(
+                1000.0 * float(creation_time)
+            )
+
+    @property
+    def expires(self):
+        """Union[datetime.datetime, None]: Datetime at which the table will be
+        deleted.
+        """
+        expiration_time = self._properties.get("expirationTime")
+        if expiration_time is not None:
+            # expiration_time will be in milliseconds.
+            return google.cloud._helpers._datetime_from_microseconds(
+                1000.0 * float(expiration_time)
+            )
+
     @property
     def project(self):
         """str: Project bound to the table."""


Test patch:
diff --git a/bigquery/tests/unit/test_table.py b/bigquery/tests/unit/test_table.py
--- a/bigquery/tests/unit/test_table.py
+++ b/bigquery/tests/unit/test_table.py
@@ -1115,11 +1115,24 @@ def _get_target_class():
     def _make_one(self, *args, **kw):
         return self._get_target_class()(*args, **kw)
 
+    def _setUpConstants(self):
+        import datetime
+        from google.cloud._helpers import UTC
+
+        self.WHEN_TS = 1437767599.125
+        self.WHEN = datetime.datetime.utcfromtimestamp(self.WHEN_TS).replace(tzinfo=UTC)
+        self.EXP_TIME = datetime.datetime(2015, 8, 1, 23, 59, 59, tzinfo=UTC)
+
     def test_ctor(self):
+        from google.cloud._helpers import _millis
+
+        self._setUpConstants()
         project = "test-project"
         dataset_id = "test_dataset"
         table_id = "coffee_table"
         resource = {
+            "creationTime": self.WHEN_TS * 1000,
+            "expirationTime": _millis(self.EXP_TIME),
             "kind": "bigquery#table",
             "id": "{}:{}.{}".format(project, dataset_id, table_id),
             "tableReference": {
@@ -1138,6 +1151,9 @@ def test_ctor(self):
         }
 
         table = self._make_one(resource)
+
+        self.assertEqual(table.created, self.WHEN)
+        self.assertEqual(table.expires, self.EXP_TIME)
         self.assertEqual(table.project, project)
         self.assertEqual(table.dataset_id, dataset_id)
         self.assertEqual(table.table_id, table_id)
@@ -1204,6 +1220,8 @@ def test_ctor_missing_properties(self):
         self.assertEqual(table.project, "testproject")
         self.assertEqual(table.dataset_id, "testdataset")
         self.assertEqual(table.table_id, "testtable")
+        self.assertIsNone(table.created)
+        self.assertIsNone(table.expires)
         self.assertIsNone(table.full_table_id)
         self.assertIsNone(table.friendly_name)
         self.assertIsNone(table.table_type)