I'm having trouble converting time.Time to Deciseconds. I basically have to port the below to Golang
Deciseconds fits into 36 bits with enough precision to record a user's consent action timing. Javascript: Math.round((new Date()).getTime()/100)
I've tried using Go / golang time.Now().UnixNano() convert to milliseconds?
to convert to milliseconds then dividing by 100. That produces the wrong time stamp. I bet this is a silly mistake on my part, but I just wanted to get some feed back
This is the method that reads the timestamp i'm trying to submit
// ReadTime reads the next 36 bits representing the epoch time in deciseconds
// and converts it to a time.Time.
func (r *ConsentReader) ReadTime() time.Time {
var ds = int64(r.ReadBits(36))
return time.Unix(ds/dsPerS, (ds%dsPerS)*nsPerDs).UTC()
}
https://github.com/LiveRamp/iabconsent/blob/328e761006ce2652bc8c0daee614381d7565c05e/parse.go#L34
I'm setting the date with
func (b bit) setDateToDeciseconds(startInclusive int, size int, t time.Time) {
deciseconds := int32(t.Unix() / 1000)
b.setNumberInt32(startInclusive, size, deciseconds)
}
func (b bit) setNumberInt32(startInclusive int, size int, to int32) {
for i := size - 1; i >= 0; i-- {
index := startInclusive + i
byteIndex := index / 8
shift := uint((byteIndex+1)*8 - index - 1)
b[byteIndex] |= byte((to % 2) << shift)
to /= 2
}
}
I keep getting date times that look like
time.Now() -> 1970-01-02 18:26:11.4 +0000 UTC