github.com/whatap/golib@v0.0.22/util/dateutil/DateUtil.go (about)

     1  package dateutil
     2  
     3  import (
     4  	//"log"
     5  	"os"
     6  	"time"
     7  )
     8  
     9  var helper = getDateTimeHelper("")
    10  
    11  func init() {
    12  	datetimeMode := os.Getenv("WHATAP_DATETIME_MODE")
    13  	if datetimeMode == "" || datetimeMode == "default" {
    14  	} else {
    15  		StartSyncTime()
    16  	}
    17  }
    18  
    19  func DateTime(time int64) string {
    20  	return helper.datetime(time)
    21  }
    22  func TimeStamp(time int64) string {
    23  	return helper.timestamp(time)
    24  }
    25  func TimeStampNow() string {
    26  	return helper.timestamp(Now())
    27  }
    28  func WeekDay(time int64) string {
    29  	return helper.weekday(time)
    30  }
    31  func GetDateUnitNow() int64 {
    32  	return helper.getDateUnit(Now())
    33  }
    34  
    35  func GetDateUnit(time int64) int64 {
    36  	return helper.getDateUnit(time)
    37  }
    38  func Ymdhms(time int64) string {
    39  	return helper.ymdhms(time)
    40  }
    41  func YYYYMMDD(time int64) string {
    42  	return helper.yyyymmdd(time)
    43  }
    44  func HHMMSS(time int64) string {
    45  	return helper.hhmmss(time)
    46  }
    47  func HHMM(time int64) string {
    48  	return helper.hhmm(time)
    49  }
    50  func YmdNow() string {
    51  	return helper.yyyymmdd(Now())
    52  }
    53  
    54  var delta int64 = 0
    55  
    56  func SystemNow() int64 {
    57  	if IsSyncTime() {
    58  		return SyncTimeMillis
    59  	}
    60  	return (time.Now().UnixMilli())
    61  }
    62  
    63  func Now() int64 {
    64  	t := SystemNow()
    65  	return t + delta
    66  }
    67  func SetDelta(t int64) {
    68  	delta = t
    69  }
    70  
    71  func SetServerTime(serverTime int64, syncfactor float64) int64 {
    72  	now := SystemNow()
    73  	delta = serverTime - now
    74  	if delta != 0 {
    75  		delta = int64(float64(delta) * syncfactor)
    76  	}
    77  	return delta
    78  }
    79  func GetDelta() int64 {
    80  	return delta
    81  }
    82  
    83  //
    84  //	func timestamp(time int64 ) string{
    85  //		return helper.timestamp(time);
    86  //	}
    87  //
    88  //	func yyyymmdd(time int64 ) string{
    89  //		return helper.yyyymmddStr(time);
    90  //	}
    91  
    92  func GetFiveMinUnit(time int64) int64 {
    93  	return helper.getFiveMinUnit(time)
    94  }
    95  
    96  func GetMinUnit(time int64) int64 {
    97  	return helper.getMinUnit(time)
    98  }
    99  
   100  func GetYmdTime(yyyyMMdd string) int64 {
   101  	return helper.getYmdTime(yyyyMMdd)
   102  }