v0.21.4 Latest Latest

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

Go to latest
Published: Jan 11, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0



Package xtime implements time related XMPP functionality.

In particular, this package implements XEP-0202: Entity Time and XEP-0082: XMPP Date and Time Profiles.




View Source
const (
	// NS is the XML namespace used by XMPP entity time requests.
	// It is provided as a convenience.
	NS = "urn:xmpp:time"

	// LegacyDateTime implements the legacy profile mentioned in XEP-0082.
	// Unless you are implementing an older XEP that specifically calls for this
	// format, time.RFC3339 should be used instead.
	LegacyDateTime = "20060102T15:04:05"


View Source
var (
	Feature = info.Feature{Var: NS}

A list of service discovery features that are supported by this package.


func Get

func Get(ctx context.Context, s *xmpp.Session, to jid.JID) (time.Time, error)

Get sends a request to the provided JID asking for its time.

func Handle

func Handle(h Handler) mux.Option

Handle returns an option that registers a Handler for entity time requests.


type Handler

type Handler struct {
	TimeFunc func() time.Time

Handler responds to requests for our time. If timeFunc is nil, time.Now is used.

func (Handler) ForFeatures added in v0.20.0

func (h Handler) ForFeatures(node string, f func(info.Feature) error) error

ForFeatures implements info.FeatureIter.

func (Handler) HandleIQ

func (h Handler) HandleIQ(iq stanza.IQ, t xmlstream.TokenReadEncoder, start *xml.StartElement) error

HandleIQ responds to entity time requests.

type Time

type Time struct {
	XMLName xml.Name `xml:"urn:xmpp:time time"`

Time is like a time.Time but it can be marshaled as an XEP-0202 time payload.

package main

import (


func main() {
	t, _ := time.Parse(time.RFC3339, "2020-02-19T06:46:00-05:00")
	xt := xtime.Time{Time: t}

	o, _ := xml.Marshal(xt)
	fmt.Printf("%s\n", o)

<time xmlns="urn:xmpp:time"><tzo>-05:00</tzo><utc>2020-02-19T11:46:00Z</utc></time>

func (Time) MarshalXML

func (t Time) MarshalXML(e *xml.Encoder, _ xml.StartElement) error

MarshalXML implements xml.Marshaler.

func (Time) MarshalXMLAttr added in v0.19.0

func (t Time) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr implements xml.MarshalerAttr.

func (Time) TokenReader

func (t Time) TokenReader() xml.TokenReader

TokenReader satisfies the xmlstream.Marshaler interface.

func (*Time) UnmarshalXML

func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler.

func (*Time) UnmarshalXMLAttr added in v0.19.0

func (t *Time) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr implements xml.UnmarshalerAttr.

func (Time) WriteXML

func (t Time) WriteXML(w xmlstream.TokenWriter) (n int, err error)

WriteXML satisfies the xmlstream.WriterTo interface. It is like MarshalXML except it writes tokens to w.

Jump to

Keyboard shortcuts

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