* dr.ink <xana...@gmail.com> [170914 10:26]:
> Hello, I have an issue with generating timestamps in golang, this is how my 
> app works. First the app generates the timestamp like this
> 
> timestamp := time.Now().UTC().Add(time.Second * 
> time.Duration(settings.TimeToLive)).Unix()
> 
> this value is then added to struct and sent to clients, clients then start 
> a countdown to that date.
> 
> Now, the issue is that *sometimes* the generated timestamps do not have the 
> given duration. For example variable *settings.TimeToLive* is set to 90, so 
> the generated timestamp should have +90 seconds to now, but it has +93 
> seconds for example.

The scenario is unclear.  Is the client on the same machine?  In the
same program in a different go routine?

How do you know the generated timestamp is now+93?  Do you have debug
statements to show that the Add() added 93?  At the site where timestamp
is generated or in the client where it is being used?  Do the server and
client have synchronized clocks (or mis-synchronized clocks)?

You are not giving enough detail to get a useful answer.

Also note that a time.Time value (as returned by time.Now) represents an
instant in time; the location (UTC, Local, etc.) only tells how the
value should be presented when formatting it.  time.Now().UTC().Unix()
is identical to time.Now().Unix() and time.Now().Local().Unix(); the
UTC() does not change the instant that the value represents.  Try

    var t = time.Now()
    fmt.Println(t.Unix(), t.UTC().Unix(), t.Local().Unix())

...Marvin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to