time

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package time provides constructors and methods for the HTML <time> element.

The <time> HTML element represents a specific period in time. It may include the datetime attribute to translate dates into machine-readable format, allowing for better search engine results or custom features such as reminders.

Index

Constants

This section is empty.

Variables

View Source
var (
	TagOpen  = []byte("<time")
	TagClose = []byte("</time>")

	AttrDateTime = []byte(" datetime=\"")
)

Byte constants for HTML rendering.

Functions

func DateTime

func DateTime(datetime string, content string) *element

DateTime creates a time element with a machine-readable datetime and human-readable display text. Uses text.Text which HTML-escapes the output. Example: time.DateTime("2023-12-25", "Christmas Day") Renders: <time datetime="2023-12-25">Christmas Day</time>

func New

func New(nodes ...node.Node) *element

New creates a new time element with optional child nodes Example: time.New() Renders: <time></time>

func RawText

func RawText(content string) *element

RawText creates a new time element with raw text content. Uses text.RawText which is not HTML-escaped. Example: time.RawText("<abbr>Dec</abbr> 25") Renders: <time><abbr>Dec</abbr> 25</time>

func RawTextf

func RawTextf(format string, args ...any) *element

RawTextf creates a new time element with formatted raw text content. Uses text.RawTextf which is not HTML-escaped. Example: time.RawTextf("<abbr>%s</abbr> %d", monthAbbr, day) Renders: <time><abbr>Jan</abbr> 15</time>

func Static

func Static(content string) *element

Static creates a new time element with static text content. Uses text.Static which is not HTML-escaped and is JIT-optimisable. Example: time.Static("Today") Renders: <time>Today</time>

func Text

func Text(content string) *element

Text creates a new time element with text content. Uses text.Text which HTML-escapes the output. Example: time.Text("25 December 2023") Renders: <time>25 December 2023</time>

func Textf

func Textf(format string, args ...any) *element

Textf creates a new time element with formatted text content. Uses text.Textf which HTML-escapes the output. Example: time.Textf("%d %s %d", day, month, year) Renders: <time>15 January 2024</time>

Types

type Element

type Element = element

Element is an exported alias for the private element type

Jump to

Keyboard shortcuts

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