prettytime

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prettytime provides utility functions for calculating and presenting in human readable and understandable form.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(t time.Time) (timeSince string)

Format returns a string describing how long it has been since the time argument passed int

Example
timeSlots := []struct {
	name string
	t    time.Time
}{
	{name: "Just now", t: time.Now()},
	{name: "Second", t: time.Now().Add(
		time.Hour*time.Duration(0) +
			time.Minute*time.Duration(0) +
			time.Second*time.Duration(1)),
	},
	{name: "SecondAgo", t: time.Now().Add(
		time.Hour*time.Duration(0) +
			time.Minute*time.Duration(0) +
			time.Second*time.Duration(-1)),
	},
	{name: "Minutes", t: time.Now().Add(time.Hour*time.Duration(0) +
		time.Minute*time.Duration(59) +
		time.Second*time.Duration(59))},
	{name: "Tomorrow", t: time.Now().AddDate(0, 0, 1)},
	{name: "Yesterday", t: time.Now().AddDate(0, 0, -1)},
	{name: "Week", t: time.Now().AddDate(0, 0, 7)},
	{name: "WeekAgo", t: time.Now().AddDate(0, 0, -7)},
	{name: "Month", t: time.Now().AddDate(0, 1, 0)},
	{name: "MonthAgo", t: time.Now().AddDate(0, -1, 0)},
	{name: "Year", t: time.Now().AddDate(2, 0, 0)},
	{name: "YearAgo", t: time.Now().AddDate(-2, 0, 0)},
}

for _, timeSlot := range timeSlots {
	fmt.Printf("%s = %v\n", timeSlot.name, Format(timeSlot.t))
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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