Documentation
¶
Index ¶
Constants ¶
View Source
const ( LangEn string = "en" // English LangRu string = "ru" // Russian LangUk string = "uk" // Ukrainian LangNl string = "nl" // Dutch LangDe string = "de" // German LangZh string = "zh" // Chinese LangBe string = "be" // Belarusian LangEs string = "es" // Spanish LangJa string = "ja" // Japanese LangFr string = "fr" // French )
View Source
const ( // OptUpcoming option removes the suffix "ago" when the date is // in the future. This option is enabled by default, there // is no need to pass it. It's available to keep backward // compatibility with the previous versions. OptUpcoming opt = "upcoming" // Upcoming option displays "OptOnline" if date interval withing // the OnlineThreshold provided in config. By default, it's // 60 seconds. For example instead of "13 seconds ago" it will // print "Online". OptOnline opt = "online" // OptJustNow option displays "Just now" if date interval withing // the JustNowThreshold provided in config. By default, it's // 60 seconds. For example instead of "32 seconds ago" it will // print "Just now". OptJustNow opt = "justNow" // OptNoSuffix option removes suffix from datetime result and get // for example "5 minutes" instead of "5 minutes ago". OptNoSuffix opt = "noSuffix" )
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure(c Config)
Configure applies the given configuration to the timeago without overriding the previous configuration. It will only override the provided configuration. If you want to override the previous configurations, use Reconfigure function instead.
func Parse ¶
Parse coverts provided datetime into `x time ago` format. The first argument can different types of inputs: 1. Unix timestamp: int, int32, int64, unit, uint32, uint64, string 2. Type from Go time package: time.Time 3. Datetime string in format 'YYYY-MM-DD HH:MM:SS': string
func Reconfigure ¶
func Reconfigure(c Config)
Reconfigure reconfigures the timeago with the provided configuration. It will override the previous configuration with the new one.
Types ¶
type Config ¶
type Config struct {
// Language is an ISO 639 language code like en, ru, de, nl, etc.
// Default: LangEn ("en").
Language string
// Location is the timezone location needed for parsing
// string date like "2019-01-01 00:00:00" to time.Time.
// If Location is not set it will default to the server's.
// Example: "America/New_York", "Europe/Moscow".
// Default: "UTC".
Location string
// Translations is a slice of language sets that can be used to
// overwrite the default translations. Read more about it in the docs
// https://time-ago.github.io/configurations.html#overwrite-translations
// Default: []LangSet{}
Translations []LangSet
// OnlineThreshold is the threshold in seconds to determine when
// Timeago should show "Online" instead of "X seconds ago". If the
// time difference is less than the threshold, it will show "Online".
// Minimum value: "1"
// Default: "60"
OnlineThreshold int
// JustNowThreshold is the threshold in seconds to determine when
// Timeago should show "Just now" instead of "X seconds ago". If the
// time difference is less than the threshold, it will show "Just now".
// Minimum value: "1"
// Default: "60"
JustNowThreshold int
}
type LangSet ¶
type LangSet struct {
Lang string `json:"lang"`
Format string `json:"format"`
Ago string `json:"ago"`
Online string `json:"online"`
JustNow string `json:"justnow"`
Second LangForms `json:"second"`
Minute LangForms `json:"minute"`
Hour LangForms `json:"hour"`
Day LangForms `json:"day"`
Week LangForms `json:"week"`
Month LangForms `json:"month"`
Year LangForms `json:"year"`
}
Click to show internal directories.
Click to hide internal directories.


