time

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeRegistry

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

func NewRegistry

func NewRegistry() *TimeRegistry

NewRegistry creates a new instance of conversion registry.

func (*TimeRegistry) Date

func (tr *TimeRegistry) Date(layout string, date any) (string, error)

Date formats a given date or current time into a specified format string.

Parameters:

layout string - the format string.
date   any    - the date to format or the current time if not a date type.

Returns:

string - the formatted date.
error - when the timezone is invalid or the date is not in a valid format.

For an example of this function in a Go template, refer to Sprout Documentation: date.

func (*TimeRegistry) DateAgo

func (tr *TimeRegistry) DateAgo(date any) string

DateAgo calculates how much time has passed since the given date.

Parameters:

date any - the starting date for the calculation.

Returns:

string - a human-readable string describing how long ago the date was.

For an example of this function in a Go template, refer to Sprout Documentation: dateAgo.

func (*TimeRegistry) DateInZone

func (tr *TimeRegistry) DateInZone(layout string, date any, zone string) (string, error)

DateInZone formats a given date or current time into a specified format string in a specified timezone.

Parameters:

layout string - the format string.
date any    - the date to format, in various acceptable formats.
zone string - the timezone name.

Returns:

string - the formatted date.
error - when the timezone is invalid or the date is not in a valid format.

For an example of this function in a Go template, refer to Sprout Documentation: dateInZone.

func (*TimeRegistry) DateModify

func (tr *TimeRegistry) DateModify(layout string, date time.Time) (time.Time, error)

DateModify adjusts a given date by a specified duration. If the duration format is incorrect, it returns an error.

Parameters:

layout string - the duration string to add to the date, such as "2h" for two hours.
date time.Time - the date to modify.

Returns:

  time.Time - the modified date after adding the duration
	 error - an error if the duration format is incorrect

For an example of this function in a Go template, refer to Sprout Documentation: dateModify.

func (*TimeRegistry) Duration

func (tr *TimeRegistry) Duration(sec any) string

Duration converts seconds into a human-readable duration string.

Parameters:

sec any - the duration in seconds.

Returns:

string - the human-readable duration.

For an example of this function in a Go template, refer to Sprout Documentation: duration.

func (*TimeRegistry) DurationRound

func (tr *TimeRegistry) DurationRound(duration any) string

DurationRound rounds a duration to the nearest significant unit, such as years or seconds.

Parameters:

duration any - the duration to round.

Returns:

string - the rounded duration.

For an example of this function in a Go template, refer to Sprout Documentation: durationRound.

func (*TimeRegistry) HtmlDate

func (tr *TimeRegistry) HtmlDate(date any) (string, error)

HtmlDate formats a date into a standard HTML date format (YYYY-MM-DD).

Parameters:

date any - the date to format.

Returns:

string - the formatted date in HTML format.
error - when the timezone is invalid or the date is not in a valid format.

For an example of this function in a Go template, refer to Sprout Documentation: htmlDate.

func (*TimeRegistry) HtmlDateInZone

func (tr *TimeRegistry) HtmlDateInZone(date any, zone string) (string, error)

HtmlDateInZone formats a date into a standard HTML date format (YYYY-MM-DD) in a specified timezone.

Parameters:

date any - the date to format.
zone string - the timezone name.

Returns:

string - the formatted date in HTML format.
error - when the timezone is invalid or the date is not in a valid format.

For an example of this function in a Go template, refer to Sprout Documentation: htmlDateInZone.

func (*TimeRegistry) LinkHandler

func (tr *TimeRegistry) LinkHandler(fh sprout.Handler) error

LinkHandler links the handler to the registry at runtime.

func (*TimeRegistry) Now

func (tr *TimeRegistry) Now() time.Time

Now returns the current time.

Returns:

time.Time - the current time.

For an example of this function in a Go template, refer to Sprout Documentation: now.

func (*TimeRegistry) RegisterAliases added in v0.6.0

func (tr *TimeRegistry) RegisterAliases(aliasesMap sprout.FunctionAliasMap) error

func (*TimeRegistry) RegisterFunctions

func (tr *TimeRegistry) RegisterFunctions(funcsMap sprout.FunctionMap) error

RegisterFunctions registers all functions of the registry.

func (*TimeRegistry) RegisterNotices added in v0.6.0

func (tr *TimeRegistry) RegisterNotices(notices *[]sprout.FunctionNotice) error

func (*TimeRegistry) UID added in v1.0.0

func (tr *TimeRegistry) UID() string

UID returns the unique identifier of the registry.

func (*TimeRegistry) UnixEpoch

func (tr *TimeRegistry) UnixEpoch(date time.Time) string

UnixEpoch returns the Unix epoch timestamp of a given date.

Parameters:

date time.Time - the date to convert to a Unix timestamp.

Returns:

string - the Unix timestamp as a string.

For an example of this function in a Go template, refer to Sprout Documentation: unixEpoch.

Jump to

Keyboard shortcuts

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