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 i18n.Locale, 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 SetNowFunc(source NowFunc)
- func Since(t time.Time) time.Duration
- func ValidateFormat(layout string, type_ LayoutType, mode LayoutMode) error
- type Date
- func (d Date) Combine(tod 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 string, loc i18n.Locale) (string, error)
- func (d *Date) Scan(value any) 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 NowFunc
- 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 Now ¶
Now returns the time now.. according to the current now function which can be switched out for testing.
func ParseDateTime ¶ added in v1.9.0
ParseDate parses the given string into a datetime
func SetNowFunc ¶ added in v1.57.1
func SetNowFunc(source NowFunc)
SetNowFunc sets the current now function
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 NowFunc ¶ added in v1.57.1
NowFunc is a function that can provide a now time
func NewFixedNow ¶ added in v1.57.1
NewFixedNow creates a new fixed now func
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(loc i18n.Locale) *Translation
GetTranslation gets the best match translation for the given locale