Skip to content

Commit

Permalink
resources,tpl: Remove duplicated same package imports in same file
Browse files Browse the repository at this point in the history
Resolves a situation when a package is imported twice in the same file.
  • Loading branch information
alexandear committed Oct 3, 2023
1 parent 4c95389 commit f7a9413
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
1 change: 0 additions & 1 deletion resources/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"image/color"
"image/draw"
"image/gif"
_ "image/gif"
_ "image/png"
"io"
"os"
Expand Down
41 changes: 20 additions & 21 deletions tpl/time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package time
import (
"fmt"
"time"
_time "time"

"github.com/gohugoio/hugo/common/htime"

Expand Down Expand Up @@ -47,7 +46,7 @@ func (ns *Namespace) AsTime(v any, args ...any) (any, error) {
if err != nil {
return nil, err
}
loc, err = _time.LoadLocation(locStr)
loc, err = time.LoadLocation(locStr)
if err != nil {
return nil, err
}
Expand All @@ -69,7 +68,7 @@ func (ns *Namespace) Format(layout string, v any) (string, error) {
}

// Now returns the current local time or `clock` time
func (ns *Namespace) Now() _time.Time {
func (ns *Namespace) Now() time.Time {
return htime.Now()
}

Expand All @@ -79,34 +78,34 @@ func (ns *Namespace) Now() _time.Time {
// such as "300ms", "-1.5h" or "2h45m".
// Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
// See https://golang.org/pkg/time/#ParseDuration
func (ns *Namespace) ParseDuration(s any) (_time.Duration, error) {
func (ns *Namespace) ParseDuration(s any) (time.Duration, error) {
ss, err := cast.ToStringE(s)
if err != nil {
return 0, err
}

return _time.ParseDuration(ss)
return time.ParseDuration(ss)
}

var durationUnits = map[string]_time.Duration{
"nanosecond": _time.Nanosecond,
"ns": _time.Nanosecond,
"microsecond": _time.Microsecond,
"us": _time.Microsecond,
"µs": _time.Microsecond,
"millisecond": _time.Millisecond,
"ms": _time.Millisecond,
"second": _time.Second,
"s": _time.Second,
"minute": _time.Minute,
"m": _time.Minute,
"hour": _time.Hour,
"h": _time.Hour,
var durationUnits = map[string]time.Duration{
"nanosecond": time.Nanosecond,
"ns": time.Nanosecond,
"microsecond": time.Microsecond,
"us": time.Microsecond,
"µs": time.Microsecond,
"millisecond": time.Millisecond,
"ms": time.Millisecond,
"second": time.Second,
"s": time.Second,
"minute": time.Minute,
"m": time.Minute,
"hour": time.Hour,
"h": time.Hour,
}

// Duration converts the given number to a time.Duration.
// Unit is one of nanosecond/ns, microsecond/us/µs, millisecond/ms, second/s, minute/m or hour/h.
func (ns *Namespace) Duration(unit any, number any) (_time.Duration, error) {
func (ns *Namespace) Duration(unit any, number any) (time.Duration, error) {
unitStr, err := cast.ToStringE(unit)
if err != nil {
return 0, err
Expand All @@ -119,5 +118,5 @@ func (ns *Namespace) Duration(unit any, number any) (_time.Duration, error) {
if err != nil {
return 0, err
}
return _time.Duration(n) * unitDuration, nil
return time.Duration(n) * unitDuration, nil
}

0 comments on commit f7a9413

Please sign in to comment.