Documentation ¶
Index ¶
- Constants
- Variables
- func DayToUTCRange(d time.Time, tz *time.Location) (time.Time, time.Time)
- func DaysBetween(date1 time.Time, date2 time.Time) int
- func Format(t time.Time, layout string, locale string, type_ LayoutType) (string, error)
- func FormatISO(date time.Time) string
- func MonthsBetween(date1 time.Time, date2 time.Time) int
- func Now() time.Time
- func ParseDateTime(layout string, value string, tz *time.Location) (time.Time, error)
- func SetNowSource(source NowSource)
- func ValidateFormat(layout string, type_ LayoutType, mode LayoutMode) error
- type Date
- func (d Date) Combine(timeOfDay TimeOfDay, tz *time.Location) time.Time
- func (d Date) Compare(other Date) int
- func (d Date) Equal(other Date) bool
- func (d Date) Format(layout, locale string) (string, error)
- func (d *Date) Scan(value interface{}) error
- func (d Date) String() string
- func (d Date) Value() (driver.Value, error)
- func (d Date) WeekNum() int
- func (d Date) Weekday() time.Weekday
- func (d Date) YearDay() int
- type LayoutMode
- type LayoutType
- type NowSource
- type TimeOfDay
- type Translation
Constants ¶
const ( DateOnlyLayouts = LayoutType(dateSeq) TimeOnlyLayouts = LayoutType(timeSeq) DateTimeLayouts = LayoutType(dateSeq | timeSeq | dateTimeSeq) )
formatting mode constants
const (
ISO8601Date = "YYYY-MM-DD"
)
Variables ¶
var ZeroDate = Date{}
ZeroDate is our uninitialized date value
var ZeroDateTime = time.Time{}
ZeroDateTime is our uninitialized datetime value
var ZeroTimeOfDay = TimeOfDay{}
ZeroTimeOfDay is our uninitialized time of day value
Functions ¶
func DayToUTCRange ¶
DayToUTCRange returns the UTC time range of the given day
func DaysBetween ¶
DaysBetween returns the number of calendar days (an int) between the two dates. Note that if these are in different timezones then the local calendar day is used for each and the difference is calculated from that.
func Format ¶ added in v1.9.0
Format formats a date/time value using a layout string.
If type is DateOnlyLayouts or DateTimeLayouts, the following sequences are accepted:
`YY` - last two digits of year 0-99 `YYYY` - four digits of your 0000-9999 `M` - month 1-12 `MM` - month 01-12 `MMM` - month Jan-Dec (localized using given locale) `MMMM` - month January-December (localized using given locale) `D` - day of month 1-31 `DD` - day of month, zero padded 0-31 `EEE` - day of week Mon-Sun (localized using given locale) `EEEE` - day of week Monday-Sunday (localized using given locale)
If type is TimeOnlyLayouts or DateTimeLayouts, the following sequences are accepted:
`h` - hour of the day 1-12 `hh` - hour of the day 01-12 `t` - twenty four hour of the day 0-23 `tt` - twenty four hour of the day 00-23 `m` - minute 0-59 `mm` - minute 00-59 `s` - second 0-59 `ss` - second 00-59 `fff` - milliseconds `ffffff` - microseconds `fffffffff` - nanoseconds `aa` - am or pm (localized using given locale) `AA` - AM or PM (localized using given locale)
If type is DateTimeLayouts, the following sequences are accepted:
`Z` - hour and minute offset from UTC, or Z for UTC `ZZZ` - hour and minute offset from UTC
The following chars are allowed and ignored: ' ', ':', ',', 'T', '-', '_', '/'
func MonthsBetween ¶
MonthsBetween returns the number of calendar months (an int) between the two dates. Note that if these are in different timezones then the local calendar day is used for each and the difference is calculated from that.
func ParseDateTime ¶ added in v1.9.0
ParseDate parses the given string into a datetime
func SetNowSource ¶
func SetNowSource(source NowSource)
SetNowSource sets the time source used by Now()
func ValidateFormat ¶ added in v1.9.0
func ValidateFormat(layout string, type_ LayoutType, mode LayoutMode) error
ValidateFormat parses a formatting layout string to validate it
Types ¶
type Date ¶
Date is a local gregorian calendar date
func ExtractDate ¶
ExtractDate extracts the date from the give datetime
type LayoutMode ¶ added in v1.9.0
type LayoutMode int
LayoutMode describes what a layout is being used for
const ( FormattingMode LayoutMode = 1 ParsingMode LayoutMode = 2 )
formatting mode constants
func (LayoutMode) String ¶ added in v1.9.0
func (m LayoutMode) String() string
String converts a layout mode to a string - used for error messages
type LayoutType ¶ added in v1.9.0
type LayoutType uint
LayoutType describes what layout sequences are permitted in a formatting operation
func (LayoutType) Includes ¶ added in v1.9.0
func (t LayoutType) Includes(seqType int) bool
Includes returns whether the given sequence type is included in this layout type
func (LayoutType) String ¶ added in v1.9.0
func (t LayoutType) String() string
String converts a layout type to a string - used for error messages
type NowSource ¶
NowSource is something that can provide a now result
var DefaultNowSource NowSource = defaultNowSource{}
DefaultNowSource is the default time source
func NewFixedNowSource ¶
NewFixedNowSource creates a new fixed time now source
func NewSequentialNowSource ¶
NewSequentialNowSource creates a new sequential time source
type TimeOfDay ¶
TimeOfDay represents a local time of day value
func ExtractTimeOfDay ¶
ExtractTimeOfDay extracts the time of day from the give datetime
func NewTimeOfDay ¶
NewTimeOfDay creates a new time of day
func ParseTimeOfDay ¶
ParseTimeOfDay parses the given string into a time of day
type Translation ¶ added in v1.9.0
type Translation struct { Days []string `json:"days"` ShortDays []string `json:"short_days"` Months []string `json:"months"` ShortMonths []string `json:"short_months"` AmPm []string `json:"am_pm"` }
func GetTranslation ¶ added in v1.9.0
func GetTranslation(locale string) *Translation
GetTranslation gets the best match translation for the given locale