From 777137eb6e4559741c0d4586346e8b53960b0d47 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 20 Apr 2018 13:08:29 +0200 Subject: [PATCH] [lib.wtime] TimeID management .GetID() --- src/git.xdrm.io/schastsp/lib/wtime/wtime.go | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/git.xdrm.io/schastsp/lib/wtime/wtime.go 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