Documentation
¶
Overview ¶
Package brimtime contains tools for working with dates and times.
Index ¶
- func AtForString(hour int, minute int, duration int) string
- func NearDateString(reference time.Time, now time.Time) string
- func SameDay(left time.Time, right time.Time) bool
- func StartOfMonth(reference time.Time) time.Time
- func StartOfWeek(reference time.Time) time.Time
- func TimeToUnixMicro(t time.Time) int64
- func TranslateDateRef(value string, biases []string, reference time.Time) time.Time
- func TranslateMonth(value string) int
- func TranslateRelativeDate(value string, reference time.Time) time.Time
- func TranslateWeekday(value string) int
- func TranslateYMD(value string, biases []string) (int, int, int)
- func UnixMicroToTime(t int64) time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtForString ¶
AtForString formats the hour, minute, and duration (in minutes) into a concise display string, such as: "@11:00" "@15:30 for 30m" "for 2h"
func NearDateString ¶
NearDateString returns a string that represents the date, with less resolution the nearer it is to now (e.g. "Thursday, the 4th of July, 2013" "Thursday the 4th"). If now.IsZero() then time.Now() will be used.
func StartOfMonth ¶
StartOfMonth returns a time for the beginning of the month, the 1st, at the same time as the reference.
func StartOfWeek ¶
StartOfWeek returns a time for the beginning of the week, Sunday, at the same time as the reference.
func TimeToUnixMicro ¶
TimeToUnixMicro returns the time as a count of microseconds within the Unix epoch.
func TranslateDateRef ¶
TranslateDateRef returns the time.Time the value represents with undetermined items filled in from the reference time.
The biases list is for the call to TranslateYMD that is made, see there for more detail but the a common setting is []string{"", "D", "MD", "YMD"}.
Note that only the date is detected with this function; any time information in the value will be ignored.
func TranslateMonth ¶
TranslateMonth returns the month the value represents, or 0 if it cannot be determined. The value may be a month name, prefix, number (e.g. "August" "Aug" "8" "08") and is not case sensitive.
func TranslateRelativeDate ¶
TranslateRelativeDate returns the time the value represents with undetermined items filled in from the reference time. The value may be various relative expressions, such as: "tomorrow", "last week", "3 weeks from now", "five days ago", etc. If the value cannot be parsed correctly, time.IsZero() will be returned.
func TranslateWeekday ¶
TranslateWeekday returns the weekday the value represents, or -1 if it cannot be determined. The value may be a weekday name, prefix, or number (e.g. "Monday" "Mon" "1" "01") and is not case sensitive.
func TranslateYMD ¶
TranslateYMD returns the year, month, and day the value represents, or zeros for the parts that cannot be determined. The biases field indicates the priority to use when guesses must be made. For example, if the value is "1-2-3", a bias of "YMD" would return 1, 2, 3 but a bias of "MDY" would return 3, 1, 2. Each bias in the list of biases is for that number of items given in the value. For example, "1-2-3" would use biases[3] as the bias, "1-2" would use biases[2], etc.; therefore the biases list should be four elements long.
The value can be of various formats, but boils down to 1-3 items separated by one of the following characters "-/., ". Each item can represent a year, month, or day and the months can be numbers, names, or prefixes. Some examples: "1-2-2014" "2-Jan-2014" "January 2, 2014" "2,jan"
A common call would be: TranslateYMD(value, []string{"", "D", "MD", "YMD"})
func UnixMicroToTime ¶
UnixMicroToTime returns the time for a given count of microseconds within the Unix epoch.
Types ¶
This section is empty.