aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/support/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/support/time.c')
-rw-r--r--src/core/support/time.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/support/time.c b/src/core/support/time.c
index 712bdf441c..5330092f56 100644
--- a/src/core/support/time.c
+++ b/src/core/support/time.c
@@ -249,3 +249,18 @@ gpr_timespec gpr_timespec_from_timeval(struct timeval t) {
ts.tv_nsec = t.tv_usec * 1000;
return ts;
}
+
+gpr_int32 gpr_time_to_millis(gpr_timespec t) {
+ if (t.tv_sec >= 2147483) {
+ if (t.tv_sec == 2147483 && t.tv_nsec < 648 * GPR_NS_PER_MS) {
+ return 2147483 * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS;
+ }
+ return 2147483647;
+ } else if (t.tv_sec <= -2147483) {
+ /* TODO(ctiller): correct handling here (it's so far in the past do we
+ care?) */
+ return -2147483648;
+ } else {
+ return t.tv_sec * GPR_MS_PER_SEC + t.tv_nsec / GPR_NS_PER_MS;
+ }
+}