Error Handling
timeago.Parse returns ("", error) when it cannot parse or process the input. Always check the returned error.
Invalid Input Type
Parse accepts int, int32, int64, uint, uint32, uint64, string, and time.Time. Any other type returns an error.
go
out, err := timeago.Parse([]int{1})
if err != nil {
// handle error
}Invalid Datetime String
Datetime strings must be in YYYY-MM-DD HH:MM:SS format. Invalid formats or invalid date values return an error.
go
out, err := timeago.Parse("25.11.2026")
if err != nil {
// handle error
}Timestamp Out of Range
Unix timestamps must be within the range that time.Unix can represent safely. Timestamps near math.MaxInt64 or math.MinInt64, and other values outside the representable range, return an error.
go
out, err := timeago.Parse(int64(math.MaxInt64))
if err != nil {
// handle error
}Invalid Configuration
If the configured language or location is invalid, Parse can return an error when it needs that configuration.
go
timeago.Reconfigure(timeago.Config{
Language: "xx",
})
out, err := timeago.Parse(time.Now())
if err != nil {
// handle error
}