Help us shape the future of Go! Take the 2026 Go Developer Survey

timestamp

package
v1.300073.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FormatLayoutMap = map[string]string{
	"%B":  "January",
	"%b":  "Jan",
	"%-m": "1",
	"%m":  "01",
	"%A":  "Monday",
	"%a":  "Mon",
	"%-d": "_2",
	"%d":  "_2",
	"%H":  "15",
	"%-I": "3",
	"%I":  "03",
	"%-M": "4",
	"%M":  "04",
	"%-S": "5",
	"%S":  "05",
	"%Y":  "2006",
	"%y":  "06",
	"%p":  "PM",
	"%Z":  "MST",
	"%z":  "-0700",
	"%f":  ".000",
}

FormatLayoutMap maps strftime directives to Go reference time layout strings.

View Source
var FormatRegexMap = map[string]string{
	"%B":  `\w{7}`,
	"%b":  `\w{3}`,
	"%-m": `\s{0,1}\d{1,2}`,
	"%m":  `\s{0,1}\d{1,2}`,
	"%A":  `\w{6,9}`,
	"%a":  `\w{3}`,
	"%-d": `\s{0,1}\d{1,2}`,
	"%d":  `\s{0,1}\d{1,2}`,
	"%H":  `\d{2}`,
	"%-I": `\d{1,2}`,
	"%I":  `\d{2}`,
	"%-M": `\d{1,2}`,
	"%M":  `\d{2}`,
	"%-S": `\d{1,2}`,
	"%S":  `\d{2}`,
	"%Y":  `\d{4}`,
	"%y":  `\d{2}`,
	"%p":  `\w{2}`,
	"%Z":  `\w{3}`,
	"%z":  `[+-]\d{4}`,
	"%f":  `(\d{1,9})`,
}

FormatRegexMap maps strftime directives to regex patterns for timestamp extraction.

View Source
var RegexEscapeMap = map[string]string{
	"^": `\^`,
	".": `\.`,
	"*": `\*`,
	"?": `\?`,
	"+": `\+`,
	"|": `\|`,
	"[": `\[`,
	"]": `\]`,
	"(": `\(`,
	")": `\)`,
	"{": `\{`,
	"}": `\}`,
	"$": `\$`,
}

RegexEscapeMap escapes characters that are special in regex but normal in the user's timestamp format string.

Functions

func BuildLayout

func BuildLayout(format string) string

BuildLayout converts a strftime format string to a Go time layout string.

func BuildRegex

func BuildRegex(format string) string

BuildRegex converts a strftime format string to a regex pattern. If the format starts with "%-m" or "%-d", the leading \s{0,1} is stripped because:

"%-m %-d %H:%M:%S" would produce regex "(\s{0,1}\d{1,2} \s{0,1}\d{1,2} \d{2}:\d{2}:\d{2})"
and layout "1 _2 15:04:05". The timestamp " 2 1 07:10:06" matches the regex but not the
layout. Stripping the prefix makes the regex and layout consistent.

func BuildRegexWithNamedCaptureGroup

func BuildRegexWithNamedCaptureGroup(format string) string

BuildRegexWithNamedCaptureGroup converts a strftime format string to a regex with a named capture group (?P<timestamp>...).

func ReplaceAll

func ReplaceAll(input string, replacements map[string]string) string

ReplaceAll replaces all occurrences of keys in the replacements map with their values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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