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
- type VDate
- func (v VDate) Date() date.Date
- func (v VDate) Day02() string
- func (v VDate) Day2() string
- func (v VDate) Day2nd() string
- func (v VDate) Format() string
- func (v VDate) IsOdd() bool
- func (v VDate) IsToday() bool
- func (v VDate) IsTomorrow() bool
- func (v VDate) IsYesterday() bool
- func (v VDate) Jan() string
- func (v VDate) January() string
- func (v VDate) MarshalText() ([]byte, error)
- func (v VDate) Mon() string
- func (v VDate) Monday() string
- func (v VDate) Month01() string
- func (v VDate) Month1() string
- func (v VDate) Next() VDateDelta
- func (v VDate) Previous() VDateDelta
- func (v VDate) String() string
- func (v *VDate) UnmarshalText(data []byte) (err error)
- func (v VDate) WithFormat(f string) VDate
- func (v VDate) Year() string
- type VDateDelta
Constants ¶
const ( // DMYFormat is a typical British representation. DMYFormat = "02/01/2006" // MDYFormat is a typical American representation. MDYFormat = "01/02/2006" // ISOFormat is ISO-8601 YYYY-MM-DD. ISOFormat = "2006-02-01" // 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 (VDate) Day2nd ¶
Day2nd returns the day number without a leading zero but with the appropriate "st", "nd", "rd", "th" suffix.
func (VDate) Format ¶
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
IsOdd returns true if the date is an odd number. This is useful for zebra striping etc.
func (VDate) IsTomorrow ¶ added in v1.1.0
IsTomorrow returns true if the date is tomorrow's date.
func (VDate) IsYesterday ¶ added in v1.1.0
IsYesterday returns true if the date is yesterday's date.
func (VDate) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
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) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. Note that the format value gets lost.
func (VDate) WithFormat ¶
WithFormat creates a new instance containing the specified format string.
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.