Documentation
¶
Overview ¶
Package dateformat formats dates by PHP date()-style patterns (entity.DateFormat). Month names come from the interface catalogs (pkg/i18n) in three forms, each its own message context: the name inside a date (F; e.g. a genitive form in some languages), the standalone name (f) and the abbreviation (M); weekday names in two (l, D).
Index ¶
- Constants
- Variables
- func Format(t time.Time, pattern, lang string) string
- func Month(lang string, m time.Month) string
- func MonthInDate(lang string, m time.Month) string
- func MonthNames(lang string) (inDate, standalone, short []string)
- func MonthShort(lang string, m time.Month) string
- func Range(start, end time.Time, datePattern, timePattern string, withTime, short bool, ...) string
- func Weekday(lang string, d time.Weekday) string
- func WeekdayNames(lang string) (full, short []string)
- func WeekdayShort(lang string, d time.Weekday) string
- type Letter
Constants ¶
const ( ContextMonthInDate = "Month name in a date" ContextMonth = "Standalone month name" ContextMonthShort = "Abbreviated month name" ContextWeekday = "Weekday name" ContextWeekdayShort = "Abbreviated weekday name" )
Message contexts of the month names.
Variables ¶
var Letters = []Letter{ {"d", i18n.N("day of the month, with a leading zero"), "01-31"}, {"j", i18n.N("day of the month, without a leading zero"), "1-31"}, {"l", i18n.N("day of the week"), ""}, {"D", i18n.N("abbreviated day of the week"), ""}, {"N", i18n.N("number of the day of the week, 1 (Monday) to 7 (Sunday)"), "1-7"}, {"m", i18n.N("month number, with a leading zero"), "01-12"}, {"n", i18n.N("month number, without a leading zero"), "1-12"}, {"F", i18n.N("month name inside a date"), ""}, {"f", i18n.N("month name on its own"), ""}, {"M", i18n.N("abbreviated month name"), ""}, {"Y", i18n.N("year, 4 digits"), "2027"}, {"y", i18n.N("year, 2 digits"), "27"}, {"H", i18n.N("hours, with a leading zero"), "00-23"}, {"G", i18n.N("hours, without a leading zero"), "0-23"}, {"h", i18n.N("hours of a 12-hour clock, with a leading zero"), "01-12"}, {"g", i18n.N("hours of a 12-hour clock, without a leading zero"), "1-12"}, {"A", i18n.N("before or after noon, upper case"), "AM, PM"}, {"a", i18n.N("before or after noon, lower case"), "am, pm"}, {"i", i18n.N("minutes"), "00-59"}, {"s", i18n.N("seconds"), "00-59"}, {`\x`, i18n.N("the character x as is"), `\x → x`}, }
Letters - the pattern letters, with Friday, 31 December 2027 as the example date.
Functions ¶
func Format ¶
Format renders t by pattern in lang (month names): the letters above are replaced, a backslash outputs the next character as is, anything else is copied.
func MonthInDate ¶
MonthInDate - month m's name inside a date in lang.
func MonthNames ¶
MonthNames - the twelve names of each form in lang, for scripts that format dates the same way (the admin's live example).
func MonthShort ¶
MonthShort - month m's abbreviated name in lang.
func Range ¶
func Range(start, end time.Time, datePattern, timePattern string, withTime, short bool, lang string) string
Range - a date (or a range from start to end; end zero - none) by datePattern, its times (withTime) by timePattern: "12 May 2027, 19:00", "12 May 2027, 19:00-21:30" (one day), "12 May 2027, 19:00 - 13 May 2027, 02:00". Without times, short shows what the two dates share once - "12-15 May 2027", "28 May - 3 June 2027" - when datePattern puts the day, the month and the year in that order; otherwise the dates are whole. The times are in the zone they come in.
func WeekdayNames ¶
WeekdayNames - the seven names of each form in lang from Sunday, for scripts that format dates the same way.