pgdatetime

package module
v0.0.0-...-54a2e63 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

pgdatetime

Github CI

Library to parse the supported DateStyles of PostgreSQL.

Documentation

Overview

Package pgdatetime supports the parsing and displaying of PostgreSQL style datetimes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(ds DateStyle, t time.Time, includeTimeZone bool) string

Format formats the given time as the given DateStyle.

func WriteToBuffer

func WriteToBuffer(buf *bytes.Buffer, ds DateStyle, t time.Time, includeTimeZone bool)

WriteToBuffer writes the given time into the given buffer.

Types

type Component

type Component uint64

Component is a component of date or time.

const (
	ComponentNumber Component = 1 << iota
	ComponentString

	ComponentDate
	ComponentTime
	ComponentTZ
	ComponentAgo

	ComponentSpecial
	ComponentEarly
	ComponentLate
	ComponentEpoch
	ComponentNow
	ComponentYesterday
	ComponentToday
	ComponentTomorrow
	ComponentZulu

	ComponentDelta
	ComponentSecond
	ComponentMinute
	ComponentHour
	ComponentDay
	ComponentWeek
	ComponentMonth
	ComponentQuarter
	ComponentYear
	ComponentDecade
	ComponentCentury
	ComponentMillennium
	ComponentMillis
	ComponentMicros
	ComponentJulian

	ComponentDOW
	ComponentDOY
	ComponentTZHour
	ComponentTZMinute
	ComponentISOYear
	ComponentISODOW

	ComponentTimeMask = (ComponentHour | ComponentMinute | ComponentSecond)
	ComponentDateMask = (ComponentDay | ComponentMonth | ComponentYear)
)

type DateStyle

type DateStyle struct {
	Order Order
	Style Style

	// FixedZonePrefix is set if we should ignore printing out the shorthand
	// timezone if it begins with this prefix.
	// Leave blank to always output timezone name.
	FixedZonePrefix string
}

DateStyle refers to the output style supported by PostgreSQL. See also: https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-DATETIME-OUTPUT

func DefaultDateStyle

func DefaultDateStyle() DateStyle

DefaultDateStyle returns the default datestyle for Postgres.

func ParseDateStyle

func ParseDateStyle(s string, existingDateStyle DateStyle) (DateStyle, error)

ParseDateStyle parses a given DateStyle.

func (*DateStyle) String

func (ds *DateStyle) String() string

type Order

type Order uint8

Order refers to the order of the date.

const (
	OrderMDY Order = iota
	OrderDMY
	OrderYMD
)

func (Order) String

func (i Order) String() string

type ParseError

type ParseError struct {
	Description string
	Idx         int
}

ParseError is an error that appears during parsing.

func NewParseError

func NewParseError(idx int, description string) *ParseError

NewParseError returns a ParseError with the given fields.

func NewParseErrorf

func NewParseErrorf(idx int, descriptionf string, args ...interface{}) *ParseError

NewParseErrorf returns a ParseError with the given fields.

func (*ParseError) Error

func (pe *ParseError) Error() string

Error implements the error interface.

type ParseResult

type ParseResult struct {
	Type ParseResultType
	Time time.Time
}

ParseResult returns the result of parsing a time.

func ParseTimestampTZ

func ParseTimestampTZ(dateStyle DateStyle, now time.Time, s string) (ParseResult, error)

ParseTimestampTZ parses a TimestampTZ element.

type ParseResultType

type ParseResultType int

ParseResultType is the type of result time returns.

const (
	// ParseResultTypeAbsoluteTime signifies an absolute return type of time.
	ParseResultTypeAbsoluteTime ParseResultType = iota
	// ParseResultTypeRelativeTime signifies time was parsed to a relative
	// to a given point in time, e.g. yesterday, today, tomorrow.
	ParseResultTypeRelativeTime
	// ParseResultTypePosInfinity signifies time is +Infinity.
	ParseResultTypePosInfinity
	// ParseResultTypeNegInfinity signifies time is -Infinity.
	ParseResultTypeNegInfinity
)

func (ParseResultType) String

func (i ParseResultType) String() string

type Style

type Style uint8

Style refers to the style of the date.

const (
	StyleISO Style = iota
	StyleSQL
	StylePostgres
	StyleGerman
)

func (Style) String

func (i Style) String() string

Jump to

Keyboard shortcuts

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