Skip to content

Commit 4a36c5c

Browse files
authored
Merge pull request #3307 from geigerj/subscription-fields
Add new subscription fields
2 parents 8f45ac8 + 8b239ed commit 4a36c5c

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

packages/google-cloud-core/google/cloud/_helpers.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,9 @@ def _timedelta_to_duration_pb(timedelta_val):
439439
:rtype: :class:`google.protobuf.duration_pb2.Duration`
440440
:returns: A duration object equivalent to the time delta.
441441
"""
442-
seconds_decimal = timedelta_val.total_seconds()
443-
# Truncate the parts other than the integer.
444-
seconds = int(seconds_decimal)
445-
if seconds_decimal < 0:
446-
signed_micros = timedelta_val.microseconds - 10**6
447-
else:
448-
signed_micros = timedelta_val.microseconds
449-
# Convert nanoseconds to microseconds.
450-
nanos = 1000 * signed_micros
451-
return duration_pb2.Duration(seconds=seconds, nanos=nanos)
442+
duration_pb = duration_pb2.Duration()
443+
duration_pb.FromTimedelta(timedelta_val)
444+
return duration_pb
452445

453446

454447
def _duration_pb_to_timedelta(duration_pb):

0 commit comments

Comments
 (0)