datefmt

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package datefmt writes dates in the language they are being read in.

Go's time package formats month and day names in English only, so {{.PublishedAt.Format "January 2, 2006"}} on a French page reads "July 30, 2026" — the one English string on an otherwise translated page. This package holds the small amount of knowledge needed to avoid that: how each language the CMS knows orders a date, and what it calls the months.

It covers the languages the CMS itself is translated into (English and French, matching the admin UI) and falls back to English formatting for any other locale, which is the same behaviour a host gets today. A site running in a language that isn't here formats its own dates in its own templates, as it always could.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Long

func Long(t time.Time, locale string) string

Long writes a date the way a sentence would: "July 30, 2026" in English, "30 juillet 2026" in French. It is what a post's date line wants, and what {{cmsDate}} renders.

The first of the month is "1er juillet" in French — the one ordinal French uses in a date, and the reason this is not a format string.

func Short

func Short(t time.Time, locale string) string

Short writes the same date with the month abbreviated: "Jul 30, 2026", "30 juil. 2026". It is for lists and tables, where the full month name costs a column its width.

func ShortTime added in v1.2.0

func ShortTime(t time.Time, locale string) string

ShortTime writes Short plus the clock: "Jul 30, 2026, 2:14 PM" in English, "30 juil. 2026, 14 h 14" in French. It is for a list where two entries can share a day and the date alone would not tell them apart — a page's publishing history, where republishing twice in an afternoon is ordinary.

French Canadian spaces the hour marker on both sides and runs on a 24-hour clock, which is why this is not Short plus a format string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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