Documentation ¶
Overview ¶
timeago allows the formatting of time in terms of fuzzy timestamps. For example:
one minute ago 3 years ago in 2 minutes
Index ¶
Constants ¶
Variables ¶
var Chinese = Config{ PastPrefix: "", PastSuffix: "前", FuturePrefix: "于 ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "1 秒", "%d 秒"}, {time.Minute, "1 分钟", "%d 分钟"}, {time.Hour, "1 小时", "%d 小时"}, {Day, "1 天", "%d 天"}, {Month, "1 月", "%d 月"}, {Year, "1 年", "%d 年"}, }, Zero: "1 秒", Max: 73 * time.Hour, DefaultLayout: "2006-01-02", }
var English = Config{ PastPrefix: "", PastSuffix: " ago", FuturePrefix: "in ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "about a second", "%d seconds"}, {time.Minute, "about a minute", "%d minutes"}, {time.Hour, "about an hour", "%d hours"}, {Day, "one day", "%d days"}, {Month, "one month", "%d months"}, {Year, "one year", "%d years"}, }, Zero: "about a second", Max: 73 * time.Hour, DefaultLayout: "2006-01-02", }
Predefined english configuration
var French = Config{ PastPrefix: "il y a ", PastSuffix: "", FuturePrefix: "dans ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "environ une seconde", "moins d'une minute"}, {time.Minute, "environ une minute", "%d minutes"}, {time.Hour, "environ une heure", "%d heures"}, {Day, "un jour", "%d jours"}, {Month, "un mois", "%d mois"}, {Year, "un an", "%d ans"}, }, Zero: "environ une seconde", Max: 73 * time.Hour, DefaultLayout: "02/01/2006", }
Predefined french configuration
var German = Config{ PastPrefix: "vor ", PastSuffix: "", FuturePrefix: "in ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "einer Sekunde", "%d Sekunden"}, {time.Minute, "einer Minute", "%d Minuten"}, {time.Hour, "einer Stunde", "%d Stunden"}, {Day, "einem Tag", "%d Tagen"}, {Month, "einem Monat", "%d Monaten"}, {Year, "einem Jahr", "%d Jahren"}, }, Zero: "einer Sekunde", Max: 73 * time.Hour, DefaultLayout: "02.01.2006", }
Predefined german configuration
var Korean = Config{ PastPrefix: "", PastSuffix: " 전", FuturePrefix: "", FutureSuffix: " 후", Periods: []FormatPeriod{ {time.Second, "약 1초", "%d초"}, {time.Minute, "약 1분", "%d분"}, {time.Hour, "약 한시간", "%d시간"}, {Day, "하루", "%d일"}, {Month, "1개월", "%d개월"}, {Year, "1년", "%d년"}, }, Zero: "방금", Max: 10 * 365 * 24 * time.Hour, DefaultLayout: "2006-01-02", }
Korean support
var Portuguese = Config{ PastPrefix: "há ", PastSuffix: "", FuturePrefix: "daqui a ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "um segundo", "%d segundos"}, {time.Minute, "um minuto", "%d minutos"}, {time.Hour, "uma hora", "%d horas"}, {Day, "um dia", "%d dias"}, {Month, "um mês", "%d meses"}, {Year, "um ano", "%d anos"}, }, Zero: "menos de um segundo", Max: 73 * time.Hour, DefaultLayout: "02-01-2006", }
var Spanish = Config{ PastPrefix: "hace ", PastSuffix: "", FuturePrefix: "en ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "un segundo", "%d segundos"}, {time.Minute, "un minuto", "%d minutos"}, {time.Hour, "una hora", "%d horas"}, {Day, "un día", "%d días"}, {Month, "un mes", "%d meses"}, {Year, "un año", "%d años"}, }, Zero: "menos de un segundo", Max: 73 * time.Hour, DefaultLayout: "02-01-2006", }
var Turkish = Config{ PastPrefix: "", PastSuffix: " önce", FuturePrefix: "", FutureSuffix: " içinde", Periods: []FormatPeriod{ {time.Second, "yaklaşık bir saniye", "%d saniye"}, {time.Minute, "yaklaşık bir dakika", "%d dakika"}, {time.Hour, "yaklaşık bir saat", "%d saat"}, {Day, "bir gün", "%d gün"}, {Month, "bir ay", "%d ay"}, {Year, "bir yıl", "%d yıl"}, }, Zero: "yaklaşık bir saniye", Max: 73 * time.Hour, DefaultLayout: "02/01/2006", }
Predefined turkish configuration
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { PastPrefix string PastSuffix string FuturePrefix string FutureSuffix string Periods []FormatPeriod Zero string Max time.Duration //Maximum duration for using the special formatting. //DefaultLayout is used if delta is greater than the minimum of last period //in Periods and Max. It is the desired representation of the date 2nd of // January 2006. DefaultLayout string }
Config allows the customization of timeago. You may configure string items (language, plurals, ...) and maximum allowed duration value for fuzzy formatting.
func WithMax ¶
WithMax creates an new config with special formatting limited to durations less than max. Values greater than max will be formatted by the standard time package using the defaultLayout.
func (Config) Format ¶
Format returns a textual representation of the time value formatted according to the layout defined in the Config. The time is compared to time.Now() and is then formatted as a fuzzy timestamp (eg. "4 days ago")
func (Config) FormatReference ¶
FormatReference is the same as Format, but the reference has to be defined by the caller