iso8601

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 2 Imported by: 6

README

iso8601

A Go library for handling ISO8601 dates.

Documentation

Overview

Package iso6801 contains a custom time type which (de)serializes in ISO8601 format.

see: https://en.wikipedia.org/wiki/ISO_8601.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Time

type Time struct {
	time.Time
}
Example
package main

import (
	"encoding/json"
	"fmt"
	"time"

	"github.com/common-fate/iso8601"
)

func main() {
	type MyStruct struct {
		CreatedAt iso8601.Time `json:"createdAt"`
	}

	s := MyStruct{
		CreatedAt: iso8601.New(time.Date(2000, 01, 01, 10, 0, 0, 0, time.UTC)),
	}

	str, _ := json.Marshal(s)

	fmt.Printf("%s", str)
}
Output:

{"createdAt":"2000-01-01T10:00:00Z"}

func New

func New(t time.Time) Time

New creates a new ISO8601 Time from a standard Go time.

func Now

func Now() Time

Now is a helper to create a ISO8601 Time at the current instant.

func (Time) MarshalJSON

func (ct Time) MarshalJSON() ([]byte, error)

MarshalJSON writes a quoted string in the custom format

func (Time) String

func (ct Time) String() string

String returns the time in ISO8601 format

func (*Time) UnmarshalJSON

func (ct *Time) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON Parses the json string in the custom format

Jump to

Keyboard shortcuts

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