forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
50 lines (44 loc) · 1.16 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"os"
"os/exec"
"runtime"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"google.golang.org/grpc"
)
func clearScreen() error {
switch runtime.GOOS {
case "windows":
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
return cmd.Run()
default:
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
return cmd.Run()
}
}
func closeConn(conn *grpc.ClientConn, cancel context.CancelFunc) {
if err := conn.Close(); err != nil {
fmt.Println(err)
}
if cancel != nil {
cancel()
}
}
// negateLocalOffset helps negate the offset of time generation
// when the unix time gets to rpcserver, it no longer is the same time
// that was sent as it handles it as a UTC value, even though when
// using starttime it is generated as your local time
// eg 2020-01-01 12:00:00 +10 will convert into
// 2020-01-01 12:00:00 +00 when at RPCServer
// so this function will minus the offset from the local sent time
// to allow for proper use at RPCServer
func negateLocalOffset(t time.Time) string {
_, offset := time.Now().Zone()
loc := time.FixedZone("", -offset)
return t.In(loc).Format(common.SimpleTimeFormat)
}