Documentation ¶
Overview ¶
Package reltime implements human-readable stringification for relative times.
Copyleft (C) 2013 Alexander Bauer
Index ¶
- func Between(t1, t2, t3 time.Time) bool
- func FormatRelative(format, fallback string, t time.Time) string
- func RelativeDay(t time.Time) string
- func RelativeWeekday(t time.Time) string
- type RelTime
- func (rt RelTime) FormatRelative(format, fallback string, t time.Time) string
- func (rt RelTime) LastWeek(t time.Time) bool
- func (rt RelTime) NextWeek(t time.Time) bool
- func (rt RelTime) RelativeDay(t time.Time) string
- func (rt RelTime) RelativeWeekday(t time.Time) string
- func (rt RelTime) ThisWeek(t time.Time) bool
- func (rt RelTime) Today(t time.Time) bool
- func (rt RelTime) Tomorrow(t time.Time) bool
- func (rt RelTime) Yesterday(t time.Time) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
Between checks whether the first time is between the next two times, t2 being inclusive and t3 being exclusive.
func RelativeDay ¶
func RelativeWeekday ¶
Types ¶
type RelTime ¶
func (RelTime) FormatRelative ¶
FormatRelative tries to format the given time relative to the RelTime as best it can, making use of available "Relative*" functions, and defaults to using time.Format with the given fallback string if it cannot. If it does succeed, it tries to substitute the produced stringification into the given format string.
For example, if myTime is a time which occurs next Tuesday at 8:05:
FormatRelative("%s at 15:04", "2006-01-02 15:04", myTime) // Next Tuesday at 08:05
func (RelTime) LastWeek ¶
LastWeek returns whether the given time is within the 7-day period ending at the start of today and beginning 24 * 7 hours earlier.
func (RelTime) NextWeek ¶
NextWeek returns whether the given time is within the 7-day period beginning at the start of today + 24 * 7 hours, and ending 24 * 7 hours later.
func (RelTime) RelativeDay ¶
RelativeString stringifies the given time relative to the RelTime. For example, it might stringify to "Tomorrow" or "Yesterday". If it is not possible to stringify to a specific relative day, it will return a blank string.
func (RelTime) RelativeWeekday ¶
RelativeWeekday stringifies the given time to a weekday name relative to the RelTime. For example, it might stringify to "Monday" or "Last Wednesday". If it is not possible to stringify to a specific relative weekday, it will return a blank string.
func (RelTime) ThisWeek ¶
ThisWeek returns whether the given time is within the 7-day period beginning at the start of today and ending 24 * 7 hours later.