github.com/hairyhenderson/gomplate/v3@v3.11.7/internal/tests/integration/time_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  	_ "time/tzdata"
     7  )
     8  
     9  func TestTime(t *testing.T) {
    10  	f := `Mon Jan 02 15:04:05 MST 2006`
    11  	i := `Fri Feb 13 23:31:30 UTC 2009`
    12  	inOutTest(t, `{{ (time.Parse "`+f+`" "`+i+`").Format "2006-01-02 15 -0700" }}`,
    13  		"2009-02-13 23 +0000")
    14  
    15  	if !isWindows {
    16  		o, e, err := cmd(t, "-i", `{{ time.ZoneName }}`).withEnv("TZ", "UTC").run()
    17  		assertSuccess(t, o, e, err, "UTC")
    18  
    19  		o, e, err = cmd(t, "-i", `{{ time.ZoneOffset }}`).withEnv("TZ", "UTC").run()
    20  		assertSuccess(t, o, e, err, "0")
    21  
    22  		o, e, err = cmd(t, "-i",
    23  			`{{ (time.ParseLocal time.Kitchen "6:00AM").Format "15:04 MST" }}`).
    24  			withEnv("TZ", "Africa/Luanda").run()
    25  		assertSuccess(t, o, e, err, "06:00 LMT")
    26  	}
    27  
    28  	zname, _ := time.Now().Zone()
    29  	inOutTest(t, `{{ time.ZoneName }}`, zname)
    30  
    31  	inOutTest(t, `{{ (time.Now).Format "2006-01-02 15 -0700" }}`,
    32  		time.Now().Format("2006-01-02 15 -0700"))
    33  
    34  	inOutTest(t, `{{ (time.ParseInLocation time.Kitchen "Africa/Luanda" "6:00AM").Format "15:04 MST" }}`,
    35  		"06:00 LMT")
    36  
    37  	inOutTest(t, `{{ (time.Unix 1234567890).UTC.Format "2006-01-02 15 -0700" }}`,
    38  		"2009-02-13 23 +0000")
    39  
    40  	inOutTest(t, `{{ (time.Unix "1234567890").UTC.Format "2006-01-02 15 -0700" }}`,
    41  		"2009-02-13 23 +0000")
    42  }