mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
@@ -23,14 +23,16 @@ import (
|
||||
func TestTimeLocation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ns := New(translators.Get("en"))
|
||||
loc, _ := time.LoadLocation("America/Antigua")
|
||||
ns := New(translators.Get("en"), loc)
|
||||
|
||||
for i, test := range []struct {
|
||||
value string
|
||||
location string
|
||||
location interface{}
|
||||
expect interface{}
|
||||
}{
|
||||
{"2020-10-20", "", "2020-10-20 00:00:00 +0000 UTC"},
|
||||
{"2020-10-20", nil, "2020-10-20 00:00:00 -0400 AST"},
|
||||
{"2020-10-20", "America/New_York", "2020-10-20 00:00:00 -0400 EDT"},
|
||||
{"2020-01-20", "America/New_York", "2020-01-20 00:00:00 -0500 EST"},
|
||||
{"2020-10-20 20:33:59", "", "2020-10-20 20:33:59 +0000 UTC"},
|
||||
@@ -41,7 +43,11 @@ func TestTimeLocation(t *testing.T) {
|
||||
{"2020-01-20", "invalid-timezone", false}, // unknown time zone invalid-timezone
|
||||
{"invalid-value", "", false},
|
||||
} {
|
||||
result, err := ns.AsTime(test.value, test.location)
|
||||
var args []interface{}
|
||||
if test.location != nil {
|
||||
args = append(args, test.location)
|
||||
}
|
||||
result, err := ns.AsTime(test.value, args...)
|
||||
if b, ok := test.expect.(bool); ok && !b {
|
||||
if err == nil {
|
||||
t.Errorf("[%d] AsTime didn't return an expected error, got %v", i, result)
|
||||
@@ -61,7 +67,7 @@ func TestTimeLocation(t *testing.T) {
|
||||
func TestFormat(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ns := New(translators.Get("en"))
|
||||
ns := New(translators.Get("en"), time.UTC)
|
||||
|
||||
for i, test := range []struct {
|
||||
layout string
|
||||
@@ -101,7 +107,7 @@ func TestFormat(t *testing.T) {
|
||||
func TestDuration(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ns := New(translators.Get("en"))
|
||||
ns := New(translators.Get("en"), time.UTC)
|
||||
|
||||
for i, test := range []struct {
|
||||
unit interface{}
|
||||
|
Reference in New Issue
Block a user