Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const DefaultCacheSize int = 16
Variables ¶
View Source
var ( German = New(german.German) AustrianGerman = New(german.AustrianGerman) )
View Source
var Best = DefaultRegistry.Best
View Source
var DefaultRegistry = &Registry{}
The global default registry. Built-in languages are automatically registered.
View Source
var English = New(english.English)
View Source
var Finnish = New(finnish.Finnish)
View Source
var Register = DefaultRegistry.Register
Functions ¶
func SetCacheSize ¶
func SetCacheSize(size int)
SetCacheSize modifies the size of the internal cache used to store previously parsed time layouts. The cache is shared across all locales and has a default size of DefaultCacheSize.
Types ¶
type Locale ¶
type Locale struct {
// contains filtered or unexported fields
}
Example (Cloned) ¶
package main import ( "fmt" "time" "github.com/hansmi/zyt" ) func main() { data := zyt.English.Data().Clone() data.Months[2].Name = "MyMarch" l := zyt.New(data) fmt.Println(l.Format("January 2006", time.Date(2000, time.March, 1, 0, 0, 0, 0, time.UTC))) }
Output: MyMarch 2000
Example (Custom) ¶
package main import ( "fmt" "time" "github.com/hansmi/zyt" "github.com/hansmi/zyt/pkg/zytdata" "golang.org/x/text/language" ) func main() { data := zytdata.LocaleData{ Tag: language.MustParse("x-custom"), Months: [12]zytdata.MonthInfo{ { Name: "MyJanuary", Abbr: "MyJan", ExtraNames: []string{"AlsoJanuary"}, }, // Other months omitted for brevity }, Days: [7]zytdata.DayInfo{ { Name: "MyMonday", Abbr: "MyMon", }, // Other days omitted for brevity }, } l := zyt.New(data) fmt.Println(l.Format("Monday, 1 January, 2006", time.Date(2001, time.January, 1, 0, 0, 0, 0, time.UTC))) ts, err := l.ParseInLocation("January 2006", "AlsoJanuary 2001", time.UTC) if err != nil { panic(err) } fmt.Println(ts.Format(time.RFC3339)) }
Output: MyMonday, 1 MyJanuary, 2001 2001-01-01T00:00:00Z
func (*Locale) Data ¶
func (l *Locale) Data() zytdata.LocaleData
func (*Locale) Format ¶
Format returns a textual representation of the time value formatted according to the layout defined by the argument. Wraps time.Time.Format.
When the layout contains a numeric form of the day and the month name, the genitive form of the month name is used if the locale has one.
func (*Locale) ParseInLocation ¶
ParseInLocation parses a formatted string and returns the time value it represents. Wraps time.ParseInLocation.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.