github.com/ztalab/ZACA@v0.0.1/pkg/caclient/transport_test.go (about) 1 package caclient 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 func TestLifespan(t *testing.T) { 10 result1, resutl2 := testLifeSpan( 11 time.Date(2021, 1, 22, 0, 0, 0, 0, time.Local), 12 time.Date(2021, 3, 22, 0, 0, 0, 0, time.Local), 13 2, 14 ) 15 fmt.Println(result1, resutl2) 16 } 17 18 func testLifeSpan(notBefore, notAfter time.Time, rate int) (remain time.Duration, ava time.Duration) { 19 now := time.Now() 20 if now.After(notAfter) { 21 return 0, 0 22 } 23 24 remain = notAfter.Sub(now) 25 26 certLong := notAfter.Sub(notBefore) 27 ava = certLong / time.Duration(rate) 28 29 fmt.Println("Surplus hours: ", remain.Hours()) 30 fmt.Println("Next replacement hours: ", ava.Hours()) 31 32 return remain, ava 33 }