Add clock cli flag

Close #8787
This commit is contained in:
satotake
2022-04-27 02:57:04 +09:00
committed by Bjørn Erik Pedersen
parent f2946da9e8
commit e77ca3c105
26 changed files with 193 additions and 37 deletions

View File

@@ -35,6 +35,7 @@ import (
)
func init() {
// htime.Now cannot be used here
rand.Seed(time.Now().UTC().UnixNano())
}

View File

@@ -25,8 +25,8 @@ import (
"reflect"
"strings"
"sync"
"time"
"github.com/gohugoio/hugo/common/htime"
texttemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
"github.com/gohugoio/hugo/helpers"
@@ -222,7 +222,7 @@ func createKey(name string, variants ...any) (partialCacheKey, error) {
var errUnHashable = errors.New("unhashable")
func (ns *Namespace) getOrCreate(ctx context.Context, key partialCacheKey, context any) (result any, err error) {
start := time.Now()
start := htime.Now()
defer func() {
if r := recover(); r != nil {
err = r.(error)

View File

@@ -28,6 +28,7 @@ func init() {
if d.Language == nil {
panic("Language must be set")
}
ctx := New(langs.GetTimeFormatter(d.Language), langs.GetLocation(d.Language))
ns := &internal.TemplateFuncsNamespace{

View File

@@ -68,9 +68,9 @@ func (ns *Namespace) Format(layout string, v any) (string, error) {
return ns.timeFormatter.Format(t, layout), nil
}
// Now returns the current local time.
// Now returns the current local time or `clock` time
func (ns *Namespace) Now() _time.Time {
return _time.Now()
return htime.Now()
}
// ParseDuration parses the duration string s.

View File

@@ -27,10 +27,10 @@ import (
"sort"
"strings"
"sync"
"time"
"unicode"
"unicode/utf8"
"github.com/gohugoio/hugo/common/htime"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/helpers"
@@ -235,7 +235,7 @@ func (t *templateExec) ExecuteWithContext(ctx context.Context, templ tpl.Templat
defer rlocker.RUnlock()
}
if t.Metrics != nil {
defer t.Metrics.MeasureSince(templ.Name(), time.Now())
defer t.Metrics.MeasureSince(templ.Name(), htime.Now())
}
if t.templateUsageTracker != nil {