iso8601

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 3 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

View Source
const Layout = "2006-01-02T15:04:05.999Z"

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 Parse added in v1.1.0

func Parse(value string) (Time, error)

Parse a string into an ISO8601 time. Returns an error if the string is not in ISO8601 format.

func (Time) MarshalDynamoDBAttributeValue added in v1.1.1

func (ct Time) MarshalDynamoDBAttributeValue() (types.AttributeValue, error)

MarshalDynamoDBAttributeValue converts a custom type to a DynamoDB attribute value.

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) UnmarshalDynamoDBAttributeValue added in v1.1.1

func (ct *Time) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error

UnmarshalDynamoDBAttributeValue converts a DynamoDB attribute value to a custom type.

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