Ejemplo n.º 1
0
def timedelta_to_duration(obj: "timedelta") -> "Duration":
    """
    Return the Python ``timestamp`` as a Protobuf ``google.protobuf.Duration``.
    """
    d = Duration()
    d.seconds = obj.total_seconds()
    d.nanos = obj.microseconds * 1000
    return d
Ejemplo n.º 2
0
def test_gcs_time_to_ms_nanos_and_seconds():
    duration = Duration()
    duration.nanos = 300000000
    duration.seconds = 5
    assert gcs_time_to_ms(duration) == 5300
Ejemplo n.º 3
0
def as_api_duration(t: timedelta) -> Duration:
    d = Duration()
    d.seconds = t.total_seconds()
    d.nanos = t.microseconds * 1000
    return d
Ejemplo n.º 4
0
def test_gcs_time_to_ms_just_nanos():
    duration = Duration()
    duration.nanos = 900000000
    assert gcs_time_to_ms(duration) == 900