strftime

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package strftime formats lys-shell's strftime-style format strings. The clock and other time-bearing modules take user formats in strftime syntax; Go layouts are never user-facing.

Index

Constants

This section is empty.

Variables

View Source
var English = Names{
	Weekdays:      [7]string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
	ShortWeekdays: [7]string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},
	Months:        [12]string{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"},
	ShortMonths:   [12]string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"},
	AM:            "AM",
	PM:            "PM",
}

English is the C locale's names.

Functions

This section is empty.

Types

type Layout

type Layout struct {
	// contains filtered or unexported fields
}

Layout is a compiled strftime format: validated once at load, then formatted per tick without re-parsing.

func Compile

func Compile(format string) (*Layout, error)

Compile validates a strftime format. Unsupported or dangling specifiers are errors — a bad format fails at load instead of rendering garbage at runtime.

func MustCompile

func MustCompile(format string) *Layout

MustCompile is Compile for a format fixed in the source, panicking when it is invalid.

func (*Layout) Format

func (l *Layout) Format(t time.Time) string

Format renders t through the compiled format with English names.

func (*Layout) FormatIn

func (l *Layout) FormatIn(t time.Time, names Names) string

FormatIn renders t through the compiled format with the given names. Literal text passes through unchanged; "%%" renders a single percent sign. A chrono padding flag between the percent and the specifier re-pads numeric fields: "-" drops the padding (%-d is "5"), "_" pads with spaces, "0" with zeros; on text fields the flag changes nothing, as in chrono.

func (*Layout) Resolution

func (l *Layout) Resolution() time.Duration

Resolution is how often the rendered text can change: a second with a seconds field in the format, otherwise a minute.

func (*Layout) String

func (l *Layout) String() string

String returns the source format.

type Names

type Names struct {
	Weekdays, ShortWeekdays [7]string
	Months, ShortMonths     [12]string
	AM, PM                  string
}

Names are the weekday and month names %A, %a, %B and %b render, indexed by time.Weekday and by time.Month minus one, and the periods %p renders before and after noon.

Jump to

Keyboard shortcuts

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