date

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Namespace

type Namespace struct {
	// contains filtered or unexported fields
}

Namespace defines the methods for dates to be used as template functions.

func New

func New(d *deps.Deps) *Namespace

Creates a new date Namespace

func (*Namespace) Ago

func (ns *Namespace) Ago(i interface{}) string

Ago

Returns a duration from the given time input in seconds. a date can be a `time.Time` or an `int, int64`.

Example: {{ ago .UpdatedAt }}

func (*Namespace) Date

func (ns *Namespace) Date(fmt string, date interface{}) (string, error)

Date

Format date by `interface{}` input, a date can be a `time.Time` or an `int, int32, int64`.

Example: {{ date "02/01/2006" now }}

func (*Namespace) DateInZone

func (ns *Namespace) DateInZone(format string, date interface{}, zone string) (string, error)

DateInZone

Takes a format, the date and zone. Casts the date to the correct format.

Returns errors.TEMPLATE if the the interface could not be cast to type time.Time

Example: {{ dateInZone "02/01/2006" now "Europe/London" }}

func (*Namespace) Duration

func (ns *Namespace) Duration(sec interface{}) string

Duration

Formats a given amount of seconds as a `time.Duration` For example `duration 85` will return `1m25s`.

Example: {{ duration 85 }}

func (*Namespace) HTMLDate

func (ns *Namespace) HTMLDate(date interface{}) (string, error)

HTMLDate

Format's a date for inserting into a HTML date picker input field.

Example: {{ htmlDate now }}

func (*Namespace) HTMLDateInZone

func (ns *Namespace) HTMLDateInZone(date interface{}, zone string) (string, error)

HTMLDateInZone

Returns HTML date with a timezone

Example: {{ htmlDateInZone now "Europe/London" }}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL