def _timedelta_to_duration_pb(timedelta_val):
 seconds_decimal = timedelta_val.total_seconds()
 seconds = int(seconds_decimal)
 if (seconds_decimal < 0):
  signed_micros = (timedelta_val.microseconds - (10 ** 6))
 else:
  signed_micros = timedelta_val.microseconds
 nanos = (1000 * signed_micros)
 return duration_pb2.Duration(seconds=seconds, nanos=nanos)

def _timedelta_to_duration_pb ( timedelta_val ) : seconds_decimal = timedelta_val . total_seconds ( ) seconds = int ( seconds_decimal ) if ( seconds_decimal < 0 ) : signed_micros = ( timedelta_val . microseconds - ( 10 ** 6 ) ) else : signed_micros = timedelta_val . microseconds nanos = ( 1000 * signed_micros ) return duration_pb2 . Duration ( seconds = seconds , nanos = nanos )
convert a python timedelta object to a duration protobuf .