github.com/developest/gtm-core@v1.0.4-0.20220111132249-cc80a3372c3f/epoch/epoch.go (about)

     1  // Copyright 2016 Michael Schenk. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package epoch
     6  
     7  import "github.com/DEVELOPEST/gtm-core/util"
     8  
     9  // WindowSize is number seconds in an epoch window
    10  const WindowSize = 60
    11  
    12  // IdleTimeout is the number of seconds to record idle events for
    13  var IdleTimeout int64 = 120
    14  
    15  // Minute rounds epoch seconds down to the nearst epoch minute
    16  func Minute(t int64) int64 {
    17  	return (t / int64(WindowSize)) * WindowSize
    18  }
    19  
    20  // MinuteNow returns the epoch minute for the current time
    21  func MinuteNow() int64 {
    22  	return Minute(util.Now().Unix())
    23  }
    24  
    25  // Now returns the current Unix time
    26  func Now() int64 {
    27  	return util.Now().Unix()
    28  }