view

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package view provides a simple API for formatting dates as strings in a manner that is easy to use in view-models, especially when using Go templates.

Index

Constants

View Source
const (
	// DMYFormat is a typical British representation.
	DMYFormat = "02/01/2006"
	// MDYFormat is a typical American representation.
	MDYFormat = "01/02/2006"
	// DefaultFormat is used by Format() unless a different format is set.
	DefaultFormat = DMYFormat
)

Variables

This section is empty.

Functions

This section is empty.

Types

type VDate

type VDate struct {
	// contains filtered or unexported fields
}

A VDate holds a Date and provides easy ways to render it, e.g. in Go templates.

func NewVDate

func NewVDate(d date.Date) VDate

NewVDate wraps a Date.

func (VDate) Date added in v1.1.0

func (v VDate) Date() date.Date

Date returns the underlying date.

func (VDate) Day02

func (v VDate) Day02() string

Day02 returns the day number with a leading zero if necessary.

func (VDate) Day2

func (v VDate) Day2() string

Day2 returns the day number without a leading zero.

func (VDate) Day2nd

func (v VDate) Day2nd() string

Day2nd returns the day number without a leading zero but with the appropriate "st", "nd", "rd", "th" suffix.

func (VDate) Format

func (v VDate) Format() string

Format formats the date using the specified format string, or "02/01/2006" by default. Use WithFormat to set this up.

func (VDate) IsOdd added in v1.2.0

func (v VDate) IsOdd() bool

IsOdd returns true if the date is an odd number. This is useful for zebra striping etc.

func (VDate) IsToday added in v1.1.0

func (v VDate) IsToday() bool

IsToday returns true if the date is today's date.

func (VDate) IsTomorrow added in v1.1.0

func (v VDate) IsTomorrow() bool

IsTomorrow returns true if the date is tomorrow's date.

func (VDate) IsYesterday added in v1.1.0

func (v VDate) IsYesterday() bool

IsYesterday returns true if the date is yesterday's date.

func (VDate) Jan

func (v VDate) Jan() string

Jan returns the month name abbreviated to three letters.

func (VDate) January

func (v VDate) January() string

January returns the full month name.

func (VDate) MarshalText

func (v VDate) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (VDate) Mon

func (v VDate) Mon() string

Mon returns the day name as three letters.

func (VDate) Monday

func (v VDate) Monday() string

Monday returns the full day name.

func (VDate) Month01

func (v VDate) Month01() string

Month01 returns the month number with a leading zero if necessary.

func (VDate) Month1

func (v VDate) Month1() string

Month1 returns the month number without a leading zero.

func (VDate) Next

func (v VDate) Next() VDateDelta

Next returns a fluent generator for later dates.

func (VDate) Previous

func (v VDate) Previous() VDateDelta

Previous returns a fluent generator for earlier dates.

func (VDate) String

func (v VDate) String() string

String formats the date in basic ISO8601 format YYYY-MM-DD.

func (*VDate) UnmarshalText

func (v *VDate) UnmarshalText(data []byte) (err error)

UnmarshalText implements the encoding.TextUnmarshaler interface. Note that the format value gets lost.

func (VDate) WithFormat

func (v VDate) WithFormat(f string) VDate

WithFormat creates a new instance containing the specified format string.

func (VDate) Year

func (v VDate) Year() string

Year returns the four-digit year.

type VDateDelta

type VDateDelta struct {
	// contains filtered or unexported fields
}

VDateDelta is a VDate with the ability to add or subtract days, weeks, months or years.

func (VDateDelta) Day

func (dd VDateDelta) Day() VDate

Day adds or subtracts one day.

func (VDateDelta) Month

func (dd VDateDelta) Month() VDate

Month adds or subtracts one month.

func (VDateDelta) Week

func (dd VDateDelta) Week() VDate

Week adds or subtracts one week.

func (VDateDelta) Year

func (dd VDateDelta) Year() VDate

Year adds or subtracts one year.

Jump to

Keyboard shortcuts

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