github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/time/test/time_test.go (about)

     1  package test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	t0 "time"
     7  
     8  	"github.com/isyscore/isc-gobase/time"
     9  )
    10  
    11  func TestTime(t *testing.T) {
    12  	t1 := time.TimeInMillis()
    13  	t2 := time.TimeInSeconds()
    14  	t3 := time.TimeInNano()
    15  	t4 := time.TimeInMicro()
    16  	t.Logf("t1: %v, t2: %v", t1, t2)
    17  	t.Logf("t3: %v, t4: %v", t3, t4)
    18  }
    19  
    20  func TestTimeBetween(t *testing.T) {
    21  	athen := t0.Date(2000, t0.January, 1, 12, 0, 0, 0, t0.UTC)
    22  	anow := t0.Date(2022, t0.March, 1, 16, 21, 0, 0, t0.UTC)
    23  	t.Logf("years between: %v", time.YearsBetween(anow, athen))
    24  	t.Logf("months between: %v", time.MonthsBetween(anow, athen))
    25  	t.Logf("days between: %v", time.DaysBetween(anow, athen))
    26  	t.Logf("hours between: %v", time.HoursBetween(anow, athen))
    27  	t.Logf("minutes between: %v", time.MinutesBetween(anow, athen))
    28  	t.Logf("seconds between: %v", time.SecondsBetween(anow, athen))
    29  	t.Logf("milliseconds between: %v", time.MilliSecondsBetween(anow, athen))
    30  }
    31  
    32  func TestTimeSpan(t *testing.T) {
    33  	athen := t0.Date(2000, t0.January, 1, 12, 0, 0, 0, t0.UTC)
    34  	anow := t0.Date(2022, t0.March, 1, 16, 21, 0, 0, t0.UTC)
    35  	t.Logf("years between: %v", time.YearSpan(anow, athen))
    36  	t.Logf("months between: %v", time.MonthSpan(anow, athen))
    37  	t.Logf("days between: %v", time.DaySpan(anow, athen))
    38  	t.Logf("hours between: %v", time.HourSpan(anow, athen))
    39  	t.Logf("minutes between: %v", time.MinuteSpan(anow, athen))
    40  	t.Logf("seconds between: %v", time.SecondSpan(anow, athen))
    41  	t.Logf("milliseconds between: %v", time.MilliSecondSpan(anow, athen))
    42  }
    43  
    44  func TestNumToTimeDuration(t *testing.T) {
    45  	data := time.NumToTimeDuration(3, t0.Hour)
    46  	fmt.Println(data.Milliseconds())
    47  }
    48  
    49  func TestParseTime(t *testing.T) {
    50  	d := time.ParseTime("20220729")
    51  	fmt.Println(time.TimeToStringYmdHmsS(d))
    52  }