utc

package
v0.0.0-...-13d2ada Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: MIT Imports: 17 Imported by: 1

Documentation

Overview

Package utc is a lightweit time struct stripped of its timezone awareness

Known limitations : dates before the year ~1678 cannot be represented with this time struct, but most of the time we can live with it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDateLong

func FormatDateLong(u UTC, lang lang.Tag) string

func FormatDateShort

func FormatDateShort(u UTC, lang lang.Tag) string

func FormatTimeShort

func FormatTimeShort(u UTC, lang lang.Tag) string

Types

type UTC

type UTC int64

UTC is the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64. Note that this means the result of calling UnixNano on the zero Time is undefined.

func Convert

func Convert(t time.Time) UTC

Convert converts a Time struct into UTC

func In

func In(d time.Duration) UTC

In returns the current time + d

func Max

func Max(l ...UTC) UTC

Max returns the latest time

func Min

func Min(l ...UTC) UTC

Min returns the earliest time

func MustParse

func MustParse(s string) UTC

MustParse is like Parse, but it panics when there is a parsing error. It simplifies safe initialisation of UTC values.

func Now

func Now() UTC

Now returns the current time.

func Parse

func Parse(s string) (UTC, error)

Parse parses a formatted string as defined by the RFC3339 and returns the time value it represents.

Note: If it returns a time.ParseError with "second out of range" when the second is equal to 60, it means it is a leap second. The go time package does not handle leap seconds. More info: https://github.com/golang/go/issues/8728 However, chances are so slim that it does not worth handling that scenario (for now)

func (UTC) Add

func (t UTC) Add(d time.Duration) UTC

Add returns the time t+d

func (UTC) BeginningOfDay

func (t UTC) BeginningOfDay() UTC

BeginningOfDay returns a new UTC with its time reset to midnight

func (UTC) Ceil

func (t UTC) Ceil(prec time.Duration) UTC

Ceil rounds date up to the given precision

func (UTC) Distance

func (t UTC) Distance(u UTC) time.Duration

Distance returns the duration t - u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned.

func (UTC) EndOfDay

func (t UTC) EndOfDay() UTC

EndOfDay returns a new UTC with its time set to the last nanosecond of the day

func (UTC) Floor

func (t UTC) Floor(prec time.Duration) UTC

Floor rounds date down to the given precision

func (*UTC) GobDecode

func (t *UTC) GobDecode(data []byte) error

GobDecode implements the gob.GobDecoder interface.

func (UTC) GobEncode

func (t UTC) GobEncode() ([]byte, error)

GobEncode implements the gob.GobEncoder interface.

func (UTC) IsZero

func (t UTC) IsZero() bool

IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.

func (UTC) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.

func (UTC) MarshalText

func (t UTC) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface It uses the default string representation from String()

func (UTC) RFC3339

func (t UTC) RFC3339() string

RFC3339 returns a string representation in RFC3339 format

func (UTC) RFC3339Nano

func (t UTC) RFC3339Nano() string

RFC3339Nano returns a string representation in RFC3339 format with nanoseconds

func (UTC) String

func (t UTC) String() string

String returns the default UTC string representation

func (UTC) Sub

func (t UTC) Sub(d time.Duration) UTC

Sub returns the time t-d

func (UTC) Time

func (t UTC) Time() time.Time

Time converts the UTC type to the standard time.Time

func (*UTC) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.

func (*UTC) UnmarshalText

func (t *UTC) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface It uses the default layout - RFC3339 with nanoseconds

Jump to

Keyboard shortcuts

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