Documentation
¶
Overview ¶
Package duration contains routines to parse standard units of time.
Package strings contains functions to manipulate strings
Index ¶
- Constants
- Variables
- func Age(s string) time.Duration
- func CamelCase(in string) string
- func HumanBytes(size interface{}) string
- func HumanDuration(duration interface{}) string
- func Indent(width int, indent, s string) string
- func KebabCase(in string) string
- func ParseDuration(val string) (*time.Duration, error)
- func Semver(version string) (*sv2.Version, error)
- func SemverCompare(constraint, version string) (bool, error)
- func ShellQuote(s string) string
- func SnakeCase(in string) string
- func Sort(list []string) []stringdeprecated
- func Trunc(length int, s string) string
- func WordWrap(in string, opts WordWrapOpts) string
- type Duration
- type InvalidDuration
- type WordWrapOpts
Constants ¶
const ( BYTE = 1 << (10 * iota) KILOBYTE MEGABYTE GIGABYTE TERABYTE PETABYTE EXABYTE )
Variables ¶
var ( Nanosecond = Duration(time.Nanosecond) Microsecond = Duration(time.Microsecond) Millisecond = Duration(time.Millisecond) Second = Duration(time.Second) Minute = Duration(time.Minute) Hour = Duration(time.Hour) Day = Hour * 24 Week = Day * 7 Fortnight = Week * 2 Month = Day * 30 // Approximation Year = Day * 365 // Approximation Decade = Year * 10 // Approximation Century = Year * 100 // Approximation Millennium = Year * 1000 // Approximation )
Standard unit of time.
var DurationAgeGen = cel.Function("Age", cel.Overload("duration.Age", []*cel.Type{cel.AnyType}, cel.DurationType, cel.UnaryBinding(age), ), )
var DurationAgeGen2 = cel.Function("age", cel.Overload("duration.age", []*cel.Type{cel.AnyType}, cel.DurationType, cel.UnaryBinding(age), ), )
var Durations = []cel.EnvOption{ cel.Function("duration", cel.Overload("double.duration", []*cel.Type{cel.DoubleType}, cel.DurationType, cel.UnaryBinding(func(value ref.Val) ref.Val { return types.Duration{Duration: time.Duration(conv.ToInt64(value.Value()))} }), ), ), cel.Function("Duration", cel.Overload("duration.Duration", []*cel.Type{cel.StringType}, cel.DurationType, cel.UnaryBinding(func(value ref.Val) ref.Val { a, err := ParseDuration(value.Value().(string)) if err != nil || a == nil { return types.Duration{} } return types.Duration{Duration: *a} }), ), ), }
var Library = append(Durations, DurationAgeGen, DurationAgeGen2, )
Functions ¶
func HumanBytes ¶ added in v3.20.4
func HumanBytes(size interface{}) string
ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:
E: Exabyte P: Petabyte T: Terabyte G: Gigabyte M: Megabyte K: Kilobyte B: Byte
The unit that results in the smallest number greater than or equal to 1 is always chosen. Input is the size in bytes.
func HumanDuration ¶ added in v3.20.4
func HumanDuration(duration interface{}) string
Returns a string representing of a duration in the form "3d1h3m".
Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. Duration more than a day or more than a week lose granularity and are truncated to resp. days-hours-minutes and weeks-days-hours. The zero duration formats as 0s.
func Indent ¶
Indent - indent each line of the string with the given indent string. Any indent characters are permitted, except for '\n'.
TODO: return an error if the indent string contains '\n' instead of succeeding
func SemverCompare ¶ added in v3.20.4
func ShellQuote ¶
ShellQuote - generate a POSIX shell literal evaluating to a string
func WordWrap ¶
func WordWrap(in string, opts WordWrapOpts) string
WordWrap - insert line-breaks into the string, before it reaches the given width.
Types ¶
type Duration ¶ added in v3.20.4
Duration is a standard unit of time.
func (Duration) Days ¶ added in v3.20.4
Days returns the duration as a floating point number of days.
func (Duration) Hours ¶ added in v3.20.4
Hours returns the duration as a floating point number of hours.
func (Duration) Minutes ¶ added in v3.20.4
Minutes returns the duration as a floating point number of minutes.
func (Duration) Nanoseconds ¶ added in v3.20.4
Nanoseconds returns the duration as an integer nanosecond count.
func (Duration) Seconds ¶ added in v3.20.4
Seconds returns the duration as a floating point number of seconds.
func (Duration) String ¶ added in v3.20.4
String returns a string representing the duration in the form "3d1h3m". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. Duration more than a day or more than a week lose granularity and are truncated to resp. days-hours-minutes and weeks-days-hours. The zero duration formats as 0s.
type InvalidDuration ¶ added in v3.20.19
type InvalidDuration struct {
Duration string
}
func (InvalidDuration) Error ¶ added in v3.20.19
func (m InvalidDuration) Error() string
type WordWrapOpts ¶
type WordWrapOpts struct { // Line-break sequence to insert (defaults to "\n") LBSeq string // The desired maximum line length in characters (defaults to 80) Width uint }
WordWrapOpts defines the options to apply to the WordWrap function