[lib.wtime] TimeID management .GetID()
This commit is contained in:
parent
064b66660c
commit
777137eb6e
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue