reltime

package module
v0.0.0-...-814bc01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2013 License: GPL-3.0 Imports: 3 Imported by: 1

README

reltime

GoDoc

Package reltime implements human-readable stringification for relative times

Documentation

Overview

Package reltime implements human-readable stringification for relative times.

Copyleft (C) 2013 Alexander Bauer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Between

func Between(t1, t2, t3 time.Time) bool

Between checks whether the first time is between the next two times, t2 being inclusive and t3 being exclusive.

func FormatRelative

func FormatRelative(format, fallback string, t time.Time) string

func RelativeDay

func RelativeDay(t time.Time) string

func RelativeWeekday

func RelativeWeekday(t time.Time) string

Types

type RelTime

type RelTime time.Time

func (RelTime) FormatRelative

func (rt RelTime) FormatRelative(format, fallback string, t time.Time) string

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

func (rt RelTime) LastWeek(t time.Time) bool

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

func (rt RelTime) NextWeek(t time.Time) bool

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

func (rt RelTime) RelativeDay(t time.Time) string

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

func (rt RelTime) RelativeWeekday(t time.Time) string

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

func (rt RelTime) ThisWeek(t time.Time) bool

ThisWeek returns whether the given time is within the 7-day period beginning at the start of today and ending 24 * 7 hours later.

func (RelTime) Today

func (rt RelTime) Today(t time.Time) bool

Today returns whether the given time is on the same day as the RelTime.

func (RelTime) Tomorrow

func (rt RelTime) Tomorrow(t time.Time) bool

Tomorrow returns whether the given time is on the day after the RelTime.

func (RelTime) Yesterday

func (rt RelTime) Yesterday(t time.Time) bool

Yesterday returns whether the given time is on the day before the RelTime.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL