github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/state/globalclock/schema.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package globalclock
     5  
     6  import (
     7  	"time"
     8  
     9  	"gopkg.in/mgo.v2/bson"
    10  )
    11  
    12  // clockDocID is the document ID for the global clock document.
    13  const clockDocID = "g"
    14  
    15  // clockDoc contains the current global virtual time.
    16  type clockDoc struct {
    17  	DocID string `bson:"_id"`
    18  	Time  int64  `bson:"time"`
    19  }
    20  
    21  func (d clockDoc) time() time.Time {
    22  	return time.Unix(0, d.Time)
    23  }
    24  
    25  func matchTimeDoc(t time.Time) bson.D {
    26  	return bson.D{
    27  		{"_id", clockDocID},
    28  		{"time", t.UnixNano()},
    29  	}
    30  }
    31  
    32  func setTimeDoc(t time.Time) bson.D {
    33  	return bson.D{{"$set", bson.D{{"time", t.UnixNano()}}}}
    34  }