[lib.wtime] TimeID management .GetID()

This commit is contained in:
xdrm-brackets 2018-04-20 13:08:29 +02:00
parent 064b66660c
commit 777137eb6e
1 changed files with 38 additions and 0 deletions

View File

@ -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<uint> 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;
}