extratime

package module
v0.0.0-...-dbe1520 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: MIT Imports: 5 Imported by: 0

README

extratime

An extra package for unmarshalling and marshalling time format to json and xml.

ci codecov go.dev reference Go Report Card

Supported Formats

  • ANSIC
  • UnixDate
  • RFC1123
  • RFC1123Z
  • RFC822
  • RFC822Z
  • RFC850
  • Kitchen
  • Stamp
  • StampMilli
  • StampMicro
  • StampNano
  • RubyDate
  • UnixTimeStamp

Install

go get github.com/johejo/extratime

Example

package extratime_test

import (
	"encoding/json"
	"encoding/xml"
	"fmt"

	"github.com/johejo/extratime"
)

type A struct {
	XMLName xml.Name          `xml:"a"`
	Text    string            `xml:",chardata"`
	B       extratime.RFC1123 `xml:"b"`
}

func Example() {
	// xml
	const x = "<a><b>Mon, 02 Jan 2006 15:04:05 MST</b></a>"
	var a A
	if err := xml.Unmarshal([]byte(x), &a); err != nil {
		panic(err)
	}
	xb, err := xml.Marshal(a)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(xb))

	// json
	const j = `{"t": "Mon, 02 Jan 2006 15:04:05 MST"}`
	var m map[string]extratime.RFC1123
	if err := json.Unmarshal([]byte(j), &m); err != nil {
		panic(err)
	}
	jb, err := json.Marshal(m)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(jb))

	// Output:
	// <a><b>Mon, 02 Jan 2006 15:04:05 MST</b></a>
	// {"t":"Mon, 02 Jan 2006 15:04:05 MST"}
}

License

MIT

Author

Mitsuo Heijo (@johejo)

Documentation

Overview

Package extratime is an extra package for unmarshalling and marshalling time format to json and xml.

Example
package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"

	"github.com/johejo/extratime"
)

type A struct {
	XMLName xml.Name          `xml:"a"`
	Text    string            `xml:",chardata"`
	B       extratime.RFC1123 `xml:"b"`
}

func main() {
	// xml
	const x = "<a><b>Mon, 02 Jan 2006 15:04:05 MST</b></a>"
	var a A
	if err := xml.Unmarshal([]byte(x), &a); err != nil {
		panic(err)
	}
	xb, err := xml.Marshal(a)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(xb))

	// json
	const j = `{"t": "Mon, 02 Jan 2006 15:04:05 MST"}`
	var m map[string]extratime.RFC1123
	if err := json.Unmarshal([]byte(j), &m); err != nil {
		panic(err)
	}
	jb, err := json.Marshal(m)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(jb))

}
Output:

<a><b>Mon, 02 Jan 2006 15:04:05 MST</b></a>
{"t":"Mon, 02 Jan 2006 15:04:05 MST"}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ANSIC

type ANSIC struct{ time.Time }

func (ANSIC) MarshalJSON

func (t ANSIC) MarshalJSON() ([]byte, error)

func (ANSIC) MarshalXML

func (t ANSIC) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*ANSIC) UnmarshalJSON

func (t *ANSIC) UnmarshalJSON(data []byte) error

func (*ANSIC) UnmarshalXML

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

type Kitchen

type Kitchen struct{ time.Time }

func (Kitchen) MarshalJSON

func (t Kitchen) MarshalJSON() ([]byte, error)

func (Kitchen) MarshalXML

func (t Kitchen) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Kitchen) UnmarshalJSON

func (t *Kitchen) UnmarshalJSON(data []byte) error

func (*Kitchen) UnmarshalXML

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

type RFC1123

type RFC1123 struct{ time.Time }

func (RFC1123) MarshalJSON

func (t RFC1123) MarshalJSON() ([]byte, error)

func (RFC1123) MarshalXML

func (t RFC1123) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RFC1123) UnmarshalJSON

func (t *RFC1123) UnmarshalJSON(data []byte) error

func (*RFC1123) UnmarshalXML

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

type RFC1123Z

type RFC1123Z struct{ time.Time }

func (RFC1123Z) MarshalJSON

func (t RFC1123Z) MarshalJSON() ([]byte, error)

func (RFC1123Z) MarshalXML

func (t RFC1123Z) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RFC1123Z) UnmarshalJSON

func (t *RFC1123Z) UnmarshalJSON(data []byte) error

func (*RFC1123Z) UnmarshalXML

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

type RFC822

type RFC822 struct{ time.Time }

func (RFC822) MarshalJSON

func (t RFC822) MarshalJSON() ([]byte, error)

func (RFC822) MarshalXML

func (t RFC822) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RFC822) UnmarshalJSON

func (t *RFC822) UnmarshalJSON(data []byte) error

func (*RFC822) UnmarshalXML

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

type RFC822Z

type RFC822Z struct{ time.Time }

func (RFC822Z) MarshalJSON

func (t RFC822Z) MarshalJSON() ([]byte, error)

func (RFC822Z) MarshalXML

func (t RFC822Z) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RFC822Z) UnmarshalJSON

func (t *RFC822Z) UnmarshalJSON(data []byte) error

func (*RFC822Z) UnmarshalXML

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

type RFC850

type RFC850 struct{ time.Time }

func (RFC850) MarshalJSON

func (t RFC850) MarshalJSON() ([]byte, error)

func (RFC850) MarshalXML

func (t RFC850) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RFC850) UnmarshalJSON

func (t *RFC850) UnmarshalJSON(data []byte) error

func (*RFC850) UnmarshalXML

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

type RubyDate

type RubyDate struct{ time.Time }

func (RubyDate) MarshalJSON

func (t RubyDate) MarshalJSON() ([]byte, error)

func (RubyDate) MarshalXML

func (t RubyDate) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*RubyDate) UnmarshalJSON

func (t *RubyDate) UnmarshalJSON(data []byte) error

func (*RubyDate) UnmarshalXML

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

type Stamp

type Stamp struct{ time.Time }

func (Stamp) MarshalJSON

func (t Stamp) MarshalJSON() ([]byte, error)

func (Stamp) MarshalXML

func (t Stamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Stamp) UnmarshalJSON

func (t *Stamp) UnmarshalJSON(data []byte) error

func (*Stamp) UnmarshalXML

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

type StampMicro

type StampMicro struct{ time.Time }

func (StampMicro) MarshalJSON

func (t StampMicro) MarshalJSON() ([]byte, error)

func (StampMicro) MarshalXML

func (t StampMicro) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*StampMicro) UnmarshalJSON

func (t *StampMicro) UnmarshalJSON(data []byte) error

func (*StampMicro) UnmarshalXML

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

type StampMilli

type StampMilli struct{ time.Time }

func (StampMilli) MarshalJSON

func (t StampMilli) MarshalJSON() ([]byte, error)

func (StampMilli) MarshalXML

func (t StampMilli) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*StampMilli) UnmarshalJSON

func (t *StampMilli) UnmarshalJSON(data []byte) error

func (*StampMilli) UnmarshalXML

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

type StampNano

type StampNano struct{ time.Time }

func (StampNano) MarshalJSON

func (t StampNano) MarshalJSON() ([]byte, error)

func (StampNano) MarshalXML

func (t StampNano) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*StampNano) UnmarshalJSON

func (t *StampNano) UnmarshalJSON(data []byte) error

func (*StampNano) UnmarshalXML

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

type UnixDate

type UnixDate struct{ time.Time }

func (UnixDate) MarshalJSON

func (t UnixDate) MarshalJSON() ([]byte, error)

func (UnixDate) MarshalXML

func (t UnixDate) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*UnixDate) UnmarshalJSON

func (t *UnixDate) UnmarshalJSON(data []byte) error

func (*UnixDate) UnmarshalXML

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

type UnixTimeStamp

type UnixTimeStamp struct{ time.Time }

func (UnixTimeStamp) MarshalJSON

func (u UnixTimeStamp) MarshalJSON() ([]byte, error)

func (UnixTimeStamp) MarshalXML

func (u UnixTimeStamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*UnixTimeStamp) UnmarshalJSON

func (u *UnixTimeStamp) UnmarshalJSON(data []byte) error

func (*UnixTimeStamp) UnmarshalXML

func (u *UnixTimeStamp) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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