Documentation
¶
Index ¶
- Constants
- func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
- func GetRandomName(retry int) string
- func RelTime(a, b time.Time, albl, blbl string) string
- func SplitPosix(line string) ([]string, error)
- func Time(then time.Time) string
- func ValidateEmail(e string) bool
- type RelTimeMagnitude
Constants ¶
const ( Day = 24 * time.Hour Week = 7 * Day Month = 30 * Day Year = 12 * Month LongTime = 37 * Year )
Seconds-based time units
Variables ¶
This section is empty.
Functions ¶
func CustomRelTime ¶ added in v1.30.13
func CustomRelTime(a, b time.Time, albl, blbl string, magnitudes []RelTimeMagnitude) string
CustomRelTime formats a time into a relative string.
It takes two times two labels and a table of relative time formats. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.
func GetRandomName ¶ added in v1.30.13
GetRandomName generates a random name from the list of adjectives and surnames in this package formatted as "adjective_surname". For example 'focused_turing'. If retry is non-zero, a random integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`
func RelTime ¶ added in v1.30.13
RelTime formats a time into a relative string.
It takes two times and two labels. In addition to the generic time delta string (e.g. 5 minutes), the labels are used applied so that the label corresponding to the smaller time is applied.
RelTime(timeInPast, timeInFuture, "earlier", "later") -> "3 weeks earlier"
func SplitPosix ¶ added in v1.30.13
SplitPosix splits a command string into words like a posix shell would
Types ¶
type RelTimeMagnitude ¶ added in v1.30.13
A RelTimeMagnitude struct contains a relative time point at which the relative format of time will switch to a new format string. A slice of these in ascending order by their "D" field is passed to CustomRelTime to format durations.
The Format field is a string that may contain a "%s" which will be replaced with the appropriate signed label (e.g. "ago" or "from now") and a "%d" that will be replaced by the quantity.
The DivBy field is the amount of time the time difference must be divided by in order to display correctly.
e.g. if D is 2*time.Minute and you want to display "%d minutes %s" DivBy should be time.Minute so whatever the duration is will be expressed in minutes.