dateformat

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 4 Imported by: 0

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

View Source
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

View Source
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

func Format(t time.Time, pattern, lang string) string

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 Month

func Month(lang string, m time.Month) string

Month - month m's standalone name in lang.

func MonthInDate

func MonthInDate(lang string, m time.Month) string

MonthInDate - month m's name inside a date in lang.

func MonthNames

func MonthNames(lang string) (inDate, standalone, short []string)

MonthNames - the twelve names of each form in lang, for scripts that format dates the same way (the admin's live example).

func MonthShort

func MonthShort(lang string, m time.Month) string

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 Weekday

func Weekday(lang string, d time.Weekday) string

Weekday - weekday d's name in lang.

func WeekdayNames

func WeekdayNames(lang string) (full, short []string)

WeekdayNames - the seven names of each form in lang from Sunday, for scripts that format dates the same way.

func WeekdayShort

func WeekdayShort(lang string, d time.Weekday) string

WeekdayShort - weekday d's abbreviated name in lang.

Types

type Letter

type Letter struct {
	Letter, Meaning, Example string
}

Letter - a pattern letter Format understands, for the admin help: Meaning is an interface string (translated where shown); a month letter's example is its month form, the others' Example as is.

func LettersIn

func LettersIn(lang string) []Letter

LettersIn - Letters with the meanings translated to lang and the month letters' examples in lang.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL