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) (time.Duration, error)
- func ParseFloat(s string) (ret float64, err error)
- func SmartDurationString(d time.Duration) string
- func SmartDurationStringEx(d time.Duration, frac bool) 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 ¶ added in v0.5.9
func AddKnownTimeFormats(format ...string)
AddKnownTimeFormats appends more time layouts to the trying list used by SmartParseTime.
func DurationFromFloat ¶ added in v0.5.9
DurationFromFloat converts a float-point number to time.Duration value.
It treats the float number as seconds. The fraction part will be transformed as ms or smaller parts.
func MstSmartParseUint ¶ added in v0.5.9
MstSmartParseUint is a helper
func MustParseComplex ¶ added in v0.5.9
func MustParseComplex(s string) (ret complex128)
MustParseComplex is a helper
func MustParseDuration ¶ added in v0.5.9
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 ¶ added in v0.5.9
MustParseFloat is a helper
func MustSmartParseInt ¶ added in v0.5.9
MustSmartParseInt is a helper
func MustSmartParseTime ¶
MustSmartParseTime parses a formatted string and returns the time value it represents.
func MustSmartParseTimePtr ¶ added in v0.5.9
MustSmartParseTimePtr parses a formatted string and returns the time value it represents.
func ParseComplex ¶ added in v0.5.9
func ParseComplex(s string) (ret complex128, err error)
ParseComplex is a helper
func ParseDuration ¶ added in v0.5.9
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".
The difference is we accept day part, such as '3d7s'.
func ParseFloat ¶ added in v0.5.9
ParseFloat is a helper
func SmartDurationString ¶ added in v0.5.9
SmartDurationString converts a time.Duration value to string.
It's better than time.Duration.String() because it produce days part. For example, 37h will be "3d1h".
func SmartDurationStringEx ¶ added in v0.5.9
SmartDurationStringEx converts a time.Duration value to string.
The boolean param 'frac' can be true, which means converter will try to format a float-point number as second part. For example, 11s13µs will be "11.000013s".
By default, such as SmartDurationString, frac shall be set true so that will produce ms, µs and ns part.
func SmartParseInt ¶ added in v0.5.9
SmartParseInt is a helper
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 ¶ added in v0.5.9
SmartParseUint is a helper
Types ¶
This section is empty.