github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/msgfmt/test/time_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  	"fmt"
     6  	"time"
     7  	. "github.com/v2pro/plz/test"
     8  	"github.com/v2pro/plz/countlog"
     9  	. "github.com/v2pro/plz/test/must"
    10  	"github.com/v2pro/plz/msgfmt"
    11  )
    12  
    13  func Test_time(t *testing.T) {
    14  	epoch := time.Unix(0, 0)
    15  	t.Run("fmt.Sprintf", Case(func(ctx *countlog.Context) {
    16  		Equal("1970-01-01 08:00:00 +0800 CST", fmt.Sprintf("%v", epoch))
    17  	}))
    18  	t.Run("msgfmt.Sprintf", Case(func(ctx *countlog.Context) {
    19  		Equal("Thu Jan  1 08:00:00 1970", msgfmt.Sprintf(
    20  			`{epoch, goTime, Mon Jan _2 15:04:05 2006}`,
    21  			"epoch", epoch))
    22  	}))
    23  	t.Run("msgfmt.Sprintf with default format", Case(func(ctx *countlog.Context) {
    24  		Equal("1970-01-01T08:00:00+08:00", msgfmt.Sprintf(
    25  			`{epoch, goTime}`,
    26  			"epoch", epoch))
    27  	}))
    28  }