diff --git a/src/git.xdrm.io/schastsp/lib/wtime/wtime.go b/src/git.xdrm.io/schastsp/lib/wtime/wtime.go new file mode 100644 index 0000000..3dec14d --- /dev/null +++ b/src/git.xdrm.io/schastsp/lib/wtime/wtime.go @@ -0,0 +1,38 @@ +package wtime + +import ( + "time" +) + + +/* (0) Definitions +---------------------------------------------------------*/ +/* (1) Time ID struct */ +type TimeID struct { ID uint; Parity uint } + + + +/* (1) Generates the current time id +* +* @wsize Window Size in seconds +* +---------------------------------------------------------*/ +func GetID(wsize uint) *TimeID{ + + /* (0) Initialise instance */ + instance := new(TimeID); + + /* (1) If wsize is 0 (div by zero possible error) */ + if wsize == 0 { return instance } + + /* (2) Get current timestamp */ + timestamp := uint( time.Now().Unix() ); + + /* (3) Calculate the time id */ + instance.ID = timestamp / wsize; + + /* (4) Calculate parity */ + instance.Parity = instance.ID % 2; + + return instance; +} \ No newline at end of file