Skip to content

hansmi/zyt

Repository files navigation

Date translator for Go

Latest release CI workflow Go reference

The zyt1 package translates month and day names from Go's time package to and from non-English languages.

When parsing multiple name variants are understood. For example the month January in German is recognized as Januar, Jänner and multiple abbreviations.

Languages using partitive and genitive cases for months and days are supported (e.g. Finnish and many Slavic languages).

Locales can be customized by users, either by defining from scratch or by cloning and modifying.

Usage

To print the current time in German:

fmt.Println(zyt.German.Format(time.RFC850, time.Now()))

To parse a timestamp in Finnish:

fmt.Println(zyt.Finnish.ParseInLocation("January 2006", "maaliskuu 2001", time.UTC))

To select the best-fitting locale:

l, _ := zyt.Best(language.BritishEnglish)
l.Format(time.RFC850, time.Now())

Supported locales

  • English
  • German
    • Austrian German
  • Finnish

Contributions to add more are very welcome.

Alternatives

Footnotes

  1. Zyt is Swiss German for time.