rfc3339

package module
v0.0.0-...-1789e3f Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 5 Imported by: 2

README

rfc3339

rfc3339 is a library that allows to manipulate durations as rfc3339

Limitations

This library handles RFC3339 up to the weeks duration. Since the months and years notions are not clear enough to me at the moment I write the library, I rather not implement it and adds the week than write an invalid code.

Examples

    package main

    import (
        "time"
        "fmt"

        "github.com/ybriffa/rfc3339"
    )

    func main() {
        s := rfc3339.FormatDuration(time.Hour)
        fmt.Println("My duration is ", s)
    }
    package main

    import (
        "time"
        "fmt"

        "github.com/ybriffa/rfc3339"
    )

    func main() {
        d, err := rfc3339.ParseDuration("PT42M")
        if err != nil {
            fmt.Println("I got an error: ", err)
            return
        }
        fmt.Println("My duration is ", d)
    }

Documentation

Index

Constants

View Source
const (
	Minute = 60
	Hour   = Minute * 60
	Day    = Hour * 24
	Week   = Day * 7
)

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration returns a textual representation of the time.Duration according to the RFC3339.

func FormatSeconds

func FormatSeconds(seconds int64) string

FormatSeconds returns a textual representation of the number of seconds according to the RFC3339.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a formatted string to a RFC3339 duration and returns the time duration it represents.

func ParseSeconds

func ParseSeconds(s string) (int64, error)

ParseSeconds parses a formatted string to a RFC3339 duration and returns the time duration it represents.

func ToStringDuration

func ToStringDuration(s string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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