github.com/primecitizens/pcz/std@v0.2.1/time/sysclock/clock_js.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  //go:build js
     5  
     6  package sysclock
     7  
     8  import (
     9  	"github.com/primecitizens/pcz/std/time"
    10  	"github.com/primecitizens/pcz/std/time/sysclock/bindings"
    11  )
    12  
    13  var (
    14  	timeOriginNS int64
    15  )
    16  
    17  func init() {
    18  	timeOriginNS = int64(bindings.TimeOriginMS() * time.Millisecond)
    19  }
    20  
    21  func Walltime() (sec int64, nsec int32) {
    22  	ms := bindings.Walltime()
    23  	return int64(ms) / 1000, int32((int64(ms) % 1000) * 1000_000)
    24  }
    25  
    26  func Nanotime() int64 {
    27  	ms := bindings.Millitime()
    28  	return timeOriginNS + int64(ms*time.Millisecond)
    29  }