blob: fa37d70964588966f5193eea776628fb2adc17cc [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Matt Rosencrantz4aabe572014-10-22 09:25:50 -07005package lib
6
Todd Wangf6a06882015-02-27 17:38:01 -08007import "time"
Matt Rosencrantz4aabe572014-10-22 09:25:50 -07008
Todd Wangf6a06882015-02-27 17:38:01 -08009// Javascript uses millisecond time units. This is both because they are the
10// native time unit, and because otherwise JS numbers would not be capable of
11// representing the full time range available to Go programs.
12//
13// TODO(bjornick,toddw): Pick a better sentry for no timeout, or change to using
14// VDL time.WireDeadline.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -070015const JSRPCNoTimeout = int64(6307200000000) // 200 years in milliseconds
Matt Rosencrantz4aabe572014-10-22 09:25:50 -070016
17func GoToJSDuration(d time.Duration) int64 {
Todd Wangf6a06882015-02-27 17:38:01 -080018 return int64(d / time.Millisecond)
Matt Rosencrantz4aabe572014-10-22 09:25:50 -070019}
20
21func JSToGoDuration(d int64) time.Duration {
Todd Wangf6a06882015-02-27 17:38:01 -080022 return time.Duration(d) * time.Millisecond
Matt Rosencrantz4aabe572014-10-22 09:25:50 -070023}