Skip to content
Monday is a minimalistic translator for month and day of week names in time.Date objects.
Go
Branch: master
Clone or download
Pull request Compare This branch is 4 commits ahead, 19 commits behind goodsign:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit Apr 12, 2013
LICENCE Initial commit. Apr 12, 2013
README.md Show writeas import path in README Jan 25, 2018
automation.go Remove dependency of package fatih/set Jul 12, 2018
automation_test.go Remove dependency of package fatih/set Jul 12, 2018
default_formats.go Fix Greek formats Jun 19, 2018
doc.go Added Bulgarian + gofmt. Apr 26, 2013
format_bg_bg.go Added Bulgarian + gofmt. Apr 26, 2013
format_ca_es.go Add locale ca_ES Dec 7, 2015
format_common.go all tests passed, need more data to test LocaleDetector Feb 15, 2016
format_cs_cz.go Adding cs_CZ locale (Fix) Feb 8, 2017
format_da_dk.go Added Bulgarian + gofmt. Apr 26, 2013
format_de_de.go Added Bulgarian + gofmt. Apr 26, 2013
format_el_gr.go Greek locale + bug fixes May 23, 2015
format_en_us.go Added Bulgarian + gofmt. Apr 26, 2013
format_es_es.go Added Bulgarian + gofmt. Apr 26, 2013
format_fi_fi.go Added Bulgarian + gofmt. Apr 26, 2013
format_fr_fr.go Added Bulgarian + gofmt. Apr 26, 2013
format_hu_hu.go Added Bulgarian + gofmt. Apr 26, 2013
format_id_id.go initial indonesian support May 19, 2016
format_it_it.go Added Bulgarian + gofmt. Apr 26, 2013
format_ja_jp.go Add Japanese translation file Jan 27, 2015
format_nb_no.go Added Bulgarian + gofmt. Apr 26, 2013
format_nl_be.go Added Bulgarian + gofmt. Apr 26, 2013
format_nn_no.go Added Bulgarian + gofmt. Apr 26, 2013
format_pl_pl.go Polish (Poland) added Oct 27, 2014
format_pt_br.go Added Bulgarian + gofmt. Apr 26, 2013
format_pt_pt.go Go fmt all the things Feb 5, 2015
format_ro_RO.go Added Bulgarian + gofmt. Apr 26, 2013
format_ru_ru.go Added Bulgarian + gofmt. Apr 26, 2013
format_sv_se.go Added Bulgarian + gofmt. Apr 26, 2013
format_tr_tr.go Added Bulgarian + gofmt. Apr 26, 2013
format_zh_cn.go Make date formats work with Japanese Jan 27, 2015
format_zh_hk.go Added Chinese (Mainland, Taiwan & Hong Kong) Apr 27, 2013
format_zh_tw.go Added Chinese (Mainland, Taiwan & Hong Kong) Apr 27, 2013
locale.go Add ability to get Locale from language Jan 25, 2018
monday.go adding fr_RE Dec 13, 2017
monday_test.go adding fr_RE Dec 13, 2017
set.go Remove dependency of package fatih/set Jul 12, 2018
set_test.go Remove dependency of package fatih/set Jul 12, 2018
utils_layout.go export months getter, make internal functions case insensitive Feb 13, 2016
utils_layout_test.go Added Bulgarian + gofmt. Apr 26, 2013

README.md

Description

Monday is a minimalistic translator for month and day of week names in time.Date objects. Supports 20+ different locales. Written in pure Go.

Installing

go get github.com/writeas/monday

Usage

Format

Given that you already use time.Format somewhere in your code, to translate your output you should import monday and replace

  yourTime.Format(yourLayout)

with

  // Change LocaleEnUS to the locale you want to use for translation
  monday.Format(yourTime, yourLayout, monday.LocaleEnUS) 

Parse

Given that you already use time.ParseInLocation somewhere in your code, to parse input string in a different language you should import monday and replace

  time.ParseInLocation(yourLayout, yourString, yourLocation)

with

  // Change LocaleEnUS to the locale you want to use for translation
  monday.ParseInLocation(yourLayout, yourString, yourLocation, monday.LocaleEnUS) 

Predefined formats

Monday declares some predefined formats: Full, Long, Medium, Short, DateTime formats for each locale. E.g. to get short format for any locale you can use map:

monday.ShortFormatsByLocale[locale]

Usage notes

Monday is not an alternative to standard time package. It is a temporary solution to use while the internationalization features are not ready.

That's why monday doesn't create any additional parsing algorithms, layout identifiers. It is just a wrapper for time.Format and time.ParseInLocation and uses all the same layout IDs, constants, etc.

So, the changes you need to temporarily switch to monday (while the internationalization features are being developed) are minimal: you preserve your layout, your time object, your parsed date string formats and the only change is the func call itself.

Locales

Supported locales are listed in locale.go file.

const (
    LocaleEnUS = "en_US" // English (United States)
    LocaleEnGB = "en_GB" // English (United Kingdom)
    LocaleDaDK = "da_DK" // Danish (Denmark)
    LocaleNlBE = "nl_BE" // Dutch (Belgium)
    LocaleNlNL = "nl_NL" // Dutch (Netherlands)
    LocaleFiFI = "fi_FI" // Finnish (Finland)
    LocaleFrFR = "fr_FR" // French (France)
    LocaleFrCA = "fr_CA" // French (Canada)
    LocaleDeDE = "de_DE" // German (Germany)
    LocaleHuHU = "hu_HU" // Hungarian (Hungary)
    LocaleItIT = "it_IT" // Italian (Italy)
    LocaleNnNO = "nn_NO" // Norwegian Nynorsk (Norway)
    LocaleNbNO = "nb_NO" // Norwegian Bokmål (Norway)
    LocalePlPL = "pl_PL" // Polish (Poland)
    LocalePtPT = "pt_PT" // Portuguese (Portugal)
    LocalePtBR = "pt_BR" // Portuguese (Brazil)
    LocaleRoRO = "ro_RO" // Romanian (Romania)
    LocaleRuRU = "ru_RU" // Russian (Russia)
    LocaleEsES = "es_ES" // Spanish (Spain)
    LocaleCaES = "ca_ES" // Catalan (Spain)
    LocaleSvSE = "sv_SE" // Swedish (Sweden)
    LocaleTrTR = "tr_TR" // Turkish (Turkey)
    LocaleBgBG = "bg_BG" // Bulgarian (Bulgaria)
    LocaleZhCN = "zh_CN" // Chinese (Mainland)
    LocaleZhTW = "zh_TW" // Chinese (Taiwan)
    LocaleZhHK = "zh_HK" // Chinese (Hong Kong)
    LocaleJaJP = "ja_JP" // Japanese (Japan)
    LocaleElGR = "el_GR" // Greek (Greece)
    LocaleIdID = "id_ID" // Indonesian (Indonesia)
    LocaleFrGP = "fr_GP" // French (Guadeloupe)
    LocaleFrLU = "fr_LU" // French (Luxembourg)
    LocaleFrMQ = "fr_MQ" // French (Martinique)
    LocaleFrGF = "fr_GF" // French (French Guiana)
    LocaleFrGF = "fr_RE" // French (Reunion)
    LocaleCsCZ = "cs_CZ" // Czech (Czech Republic)
)

LocaleDetector

    var timeLocaleDetector *monday.LocaleDetector = monday.NewLocaleDetector()
    dateTime, err := timeLocaleDetector.Parse(layout,datestr) 

parses datetime with unknown locale (for now - layout must be defined, as for time.Parse())

useful for text parsing tools/crawlers (f.e.: rss-feeds crawler)

TODO:

  • make LocaleDetector insensitive to whitespaces count

Thread-safety

Monday initializes all its data once in the init func and then uses only func calls and local vars. Thus, it's thread-safe and doesn't need any mutexes to be used with.

Monday Licence

The Monday library is released under the BSD Licence

LICENCE file

Thanks

You can’t perform that action at this time.