diff options
author | satotake <[email protected]> | 2022-04-27 02:57:04 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-05-08 16:56:26 +0200 |
commit | e77ca3c105bd64c5077d823d2127f6f812a4f681 (patch) | |
tree | ebbe9c310bfab1e34f9fd2e36b738fd2a37d6f11 /tpl | |
parent | f2946da9e806c2bafbdd26707fe339db79bd980b (diff) | |
download | hugo-e77ca3c105bd64c5077d823d2127f6f812a4f681.tar.gz hugo-e77ca3c105bd64c5077d823d2127f6f812a4f681.zip |
Add `clock` cli flag
Close #8787
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/collections/collections.go | 1 | ||||
-rw-r--r-- | tpl/partials/partials.go | 4 | ||||
-rw-r--r-- | tpl/time/init.go | 1 | ||||
-rw-r--r-- | tpl/time/time.go | 4 | ||||
-rw-r--r-- | tpl/tplimpl/template.go | 4 |
5 files changed, 8 insertions, 6 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 516e2c272..8fdc85275 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -35,6 +35,7 @@ import ( ) func init() { + // htime.Now cannot be used here rand.Seed(time.Now().UTC().UnixNano()) } diff --git a/tpl/partials/partials.go b/tpl/partials/partials.go index eb4ebfe32..9ded32a71 100644 --- a/tpl/partials/partials.go +++ b/tpl/partials/partials.go @@ -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) diff --git a/tpl/time/init.go b/tpl/time/init.go index 4bb2ddf67..7dd71f210 100644 --- a/tpl/time/init.go +++ b/tpl/time/init.go @@ -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{ diff --git a/tpl/time/time.go b/tpl/time/time.go index 623b7206a..cd78b83aa 100644 --- a/tpl/time/time.go +++ b/tpl/time/time.go @@ -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. diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index c092ff638..d352f02e8 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -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 { |