time.pyx.pxi 1.0 KB

1234567891011121314151617181920212223242526272829
  1. # Copyright 2018 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. cdef gpr_timespec _timespec_from_time(object time) except *:
  15. if time is None:
  16. return gpr_inf_future(GPR_CLOCK_REALTIME)
  17. else:
  18. return gpr_time_from_nanos(
  19. <int64_t>(<double>time * GPR_NS_PER_SEC),
  20. GPR_CLOCK_REALTIME,
  21. )
  22. cdef double _time_from_timespec(gpr_timespec timespec) except *:
  23. cdef gpr_timespec real_timespec = gpr_convert_clock_type(
  24. timespec, GPR_CLOCK_REALTIME)
  25. return gpr_timespec_to_micros(real_timespec) / GPR_US_PER_SEC