gitee.com/quant1x/gox@v1.21.2/timestamp/timestamp_test.go (about)

     1  package timestamp
     2  
     3  import (
     4  	"fmt"
     5  	"gitee.com/quant1x/gox/api"
     6  	//"github.com/golang-module/carbon/v2"
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  func TestTimePrivate(t *testing.T) {
    12  	v := unixToInternal
    13  	fmt.Println(v)
    14  }
    15  
    16  func TestYMDHMS_SSS(t *testing.T) {
    17  	ms := Now()
    18  	ts := Timestamp(ms)
    19  	fmt.Println(ts.DateTime())
    20  	fmt.Println(ts)
    21  }
    22  
    23  func TestNow(t *testing.T) {
    24  	now := Now()
    25  	fmt.Println("today1 :", now-now%MillisecondsPerDay)
    26  	fmt.Println("today2 :", ZeroHour(now))
    27  	fmt.Println("today3 :", Today())
    28  	fmt.Println("  h :", (now%MillisecondsPerDay)/MillisecondsPerHour)
    29  	fmt.Println("  m :", (now%MillisecondsPerHour)/MillisecondsPerMinute)
    30  	fmt.Println("  s :", (now%MillisecondsPerMinute)/MillisecondsPerSecond)
    31  	fmt.Println("sss :", now%MillisecondsPerSecond)
    32  
    33  	fmt.Println(now % MillisecondsPerDay)
    34  
    35  	date := "2024-01-07"
    36  	tm, err := api.ParseTime(date)
    37  	fmt.Println(tm, err)
    38  	fmt.Println(tm.Date())
    39  	ts := tm.Local().Unix()
    40  	ts = tm.UnixMilli()
    41  	fmt.Println("today1 :", ts)
    42  	ts = tm.Local().UnixMilli()
    43  	fmt.Println("today2 :", ts+int64(offsetInSecondsEastOfUTC*MillisecondsPerSecond))
    44  	t1 := time.Unix(ts/1000, 0)
    45  	fmt.Println("t1 =>", t1)
    46  	t3 := TimeToTimestamp(tm)
    47  	fmt.Println("t3 =>", t3)
    48  	t4 := Time(t3)
    49  	fmt.Println("t4 =>", t4)
    50  
    51  	t2 := time.UnixMilli(now) //.UTC()
    52  	fmt.Println("t2 =>", t2)
    53  }
    54  
    55  func TestTime1(t *testing.T) {
    56  	formatTimeStr := "2017-04-11 13:33:37"
    57  	formatTime, err := time.Parse("2006-01-02 15:04:05", formatTimeStr)
    58  	if err == nil {
    59  		fmt.Println(formatTime) //打印结果:2017-04-11 13:33:37 +0000 UTC
    60  		fmt.Println(formatTime.Unix())
    61  	}
    62  }
    63  
    64  //func TestTime2(t *testing.T) {
    65  //	// 今天此刻
    66  //	fmt.Printf("%s", carbon.Now()) // 2020-08-05 13:14:15
    67  //}
    68  
    69  func TestTime3(t *testing.T) {
    70  	t1 := zeroTime.UnixMilli()
    71  	fmt.Println(t1)
    72  	t2 := time.Now()
    73  	fmt.Println(t2)
    74  	t3 := time.Since(t2)
    75  	fmt.Println(t3.Seconds())
    76  }
    77  
    78  func TestSinceZeroHour(t *testing.T) {
    79  	now := time.Now()
    80  	t1 := SinceZeroHour(now)
    81  	fmt.Println(t1)
    82  	t2 := Since(now)
    83  	fmt.Println(t2)
    84  }
    85  
    86  func BenchmarkTimestamp_release(b *testing.B) {
    87  	for i := 0; i < b.N; i++ {
    88  		tm := Now()
    89  		_ = tm
    90  	}
    91  }
    92  
    93  func BenchmarkTimestamp_v0(b *testing.B) {
    94  	for i := 0; i < b.N; i++ {
    95  		now := time.Now()
    96  		tm := now.UnixMilli()
    97  		_ = tm
    98  	}
    99  }
   100  
   101  func BenchmarkTimestamp_v1(b *testing.B) {
   102  	for i := 0; i < b.N; i++ {
   103  		tm := v1Now()
   104  		_ = tm
   105  	}
   106  }
   107  
   108  func BenchmarkTimestamp_v2(b *testing.B) {
   109  	for i := 0; i < b.N; i++ {
   110  		tm := v2Now()
   111  		_ = tm
   112  	}
   113  }