Documentation
¶
Index ¶
- func AddKnownTimeFormats(format ...string)
- func DurationFromFloat(f float64) time.Duration
- func MstSmartParseUint(s string) (ret uint64)
- func MustParseComplex(s string) (ret complex128)
- func MustParseDuration(s string) (dur time.Duration)
- func MustParseFloat(s string) (ret float64)
- func MustSmartParseInt(s string) (ret int64)
- func MustSmartParseTime(str string) (tm time.Time)
- func MustSmartParseTimePtr(str string) (tm *time.Time)
- func ParseComplex(s string) (ret complex128, err error)
- func ParseDuration(s string) (dur time.Duration, err error)
- func ParseFloat(s string) (ret float64, err error)
- func RoundTime(roundTo string, value time.Time) string
- func SmartParseInt(s string) (ret int64, err error)
- func SmartParseTime(str string) (tm time.Time, err error)
- func SmartParseUint(s string) (ret uint64, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddKnownTimeFormats ¶
func AddKnownTimeFormats(format ...string)
AddKnownTimeFormats appends more time layouts to the trying list used by SmartParseTime.
func DurationFromFloat ¶
func MstSmartParseUint ¶
func MustParseComplex ¶
func MustParseComplex(s string) (ret complex128)
func MustParseDuration ¶
MustParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
func MustParseFloat ¶
func MustSmartParseInt ¶
func MustSmartParseTime ¶
MustSmartParseTime parses a formatted string and returns the time value it represents.
func MustSmartParseTimePtr ¶
MustSmartParseTimePtr parses a formatted string and returns the time value it represents.
func ParseComplex ¶
func ParseComplex(s string) (ret complex128, err error)
func ParseDuration ¶
ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
func ParseFloat ¶
func RoundTime ¶
RoundTime strips small ticks from a time.Time value. For example:
assert.True(RoundTime("h", SmartParseTime("5:11:22")), SmartParseTime("5:0:0"))
func SmartParseInt ¶
func SmartParseTime ¶
SmartParseTime parses a formatted string and returns the time value it represents.
The example for [time.Time.Format()] demonstrates the working of the layout string in detail and is a good reference.
When parsing (only), the input may contain a fractional second field immediately after the seconds field, even if the layout does not signify its presence. In that case either a comma or a decimal point followed by a maximal series of digits is parsed as a fractional second. Fractional seconds are truncated to nanosecond precision.
Elements omitted from the layout are assumed to be zero or, when zero is impossible, one, so parsing "3:04pm" returns the time corresponding to Jan 1, year 0, 15:04:00 UTC (note that because the year is 0, this time is before the zero Time). Years must be in the range 0000..9999. The day of the week is checked for syntax but it is otherwise ignored.
For layouts specifying the two-digit year 06, a value NN >= 69 will be treated as 19NN and a value NN < 69 will be treated as 20NN.
The remainder of this comment describes the handling of time zones.
In the absence of a time zone indicator, Parse returns a time in UTC.
When parsing a time with a zone offset like -0700, if the offset corresponds to a time zone used by the current location (Local), then Parse uses that location and zone in the returned time. Otherwise it records the time as being in a fabricated location with time fixed at the given zone offset.
When parsing a time with a zone abbreviation like MST, if the zone abbreviation has a defined offset in the current location, then that offset is used. The zone abbreviation "UTC" is recognized as UTC regardless of location. If the zone abbreviation is unknown, Parse records the time as being in a fabricated location with the given zone abbreviation and a zero offset. This choice means that such a time can be parsed and reformatted with the same layout losslessly, but the exact instant used in the representation will differ by the actual zone offset. To avoid such problems, prefer time layouts that use a numeric zone offset, or use ParseInLocation.
func SmartParseUint ¶
Types ¶
This section is empty.