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 ¶
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.
Click to show internal directories.
Click to hide internal directories.