Documentation
¶
Overview ¶
fmtdate provides a date formatter and parser using the syntax of Microsoft Excel (TM).
Additionally it offers default conversions for date time and datetime.
Why?
Microsoft Excel (TM) has a well known syntax for date formatting, that more memorable than the syntax chosen in the time package in the go library.
Usage
package main import ( "gitlab.com/golang-utils/fmtdate" "fmt" ) func main() { date := fmtdate.Format("DD.MM.YYYY", time.Now()) fmt.Println(date) var err date, err = fmtdate.Parse("M/D/YY", "2/3/07") fmt.Println(date, err) }
Formats
M - month (1) MM - month (01) MMM - month (Jan) MMMM - month (January) D - day (2) DD - day (02) DDD - day (Mon) DDDD - day (Monday) YY - year (06) YYYY - year (2006) hh - hours (15) mm - minutes (04) ss - seconds (05)
AM/PM hours: 'h' followed by optional 'mm' and 'ss' followed by 'pm', e.g.
hpm - hours (03PM) h:mmpm - hours:minutes (03:04PM) h:mm:sspm - hours:minutes:seconds (03:04:05PM)
Time zones: a time format followed by 'ZZZZ', 'ZZZ' or 'ZZ', e.g.
hh:mm:ss ZZZZ (16:05:06 +0100) hh:mm:ss ZZZ (16:05:06 CET) hh:mm:ss ZZ (16:05:06 +01:00)
Index ¶
- Variables
- func DaysAgo(t time.Time, numdaysAgo int) time.Time
- func DaysAhead(t time.Time, numdaysAhead int) time.Time
- func FirstDayInMonthsAgo(t time.Time, numMonthsAgo int) time.Time
- func FirstDayInMonthsAhead(t time.Time, numMonthsAhead int) time.Time
- func Format(format string, date time.Time) string
- func FormatDate(date time.Time) string
- func FormatDateTime(date time.Time) string
- func FormatTime(date time.Time) string
- func LastDayInMonthsAgo(t time.Time, numMonthsAgo int) time.Time
- func LastDayInMonthsAhead(t time.Time, numMonthsAhead int) time.Time
- func MonthsAgo(t time.Time, numMonthsAgo int) time.Time
- func MonthsAhead(t time.Time, numMonthsAhead int) time.Time
- func MustParse(format string, value string) time.Time
- func MustParseDate(value string) time.Time
- func MustParseDateTime(value string) time.Time
- func MustParseTime(value string) time.Time
- func Parse(format string, value string) (time.Time, error)
- func ParseDate(value string) (time.Time, error)
- func ParseDateTime(value string) (time.Time, error)
- func ParseTime(value string) (time.Time, error)
- func SetDay(t time.Time, day int) time.Time
- func SetMonth(t time.Time, month int) time.Time
- func SetYear(t time.Time, year int) time.Time
- func Translate(fmt string) string
- func YearsAgo(t time.Time, numYearsAgo int) time.Time
- func YearsAhead(t time.Time, numYearsAhead int) time.Time
- type ParseError
- type TimeDate
Constants ¶
This section is empty.
Variables ¶
var ( DefaultTimeFormat = "hh:mm:ss" DefaultDateFormat = "YYYY-MM-DD" DefaultDateTimeFormat = "YYYY-MM-DD hh:mm:ss" )
var Placeholder = []p{
{"hh", "15"},
{"h", "03"},
{"mm", "04"},
{"ss", "05"},
{"MMMM", "January"},
{"MMM", "Jan"},
{"MM", "01"},
{"M", "1"},
{"pm", "PM"},
{"ZZZZ", "-0700"},
{"ZZZ", "MST"},
{"ZZ", "Z07:00"},
{"YYYY", "2006"},
{"YY", "06"},
{"DDDD", "Monday"},
{"DDD", "Mon"},
{"DD", "02"},
{"D", "2"},
}
Functions ¶
func FirstDayInMonthsAgo ¶ added in v1.0.5
func FirstDayInMonthsAhead ¶ added in v1.0.5
func FormatDate ¶
FormatDate formats the given date to the DefaultDateFormat
func FormatDateTime ¶
FormatTime formats the given date to the DefaultDateTimeFormat
func FormatTime ¶
FormatTime formats the given date to the DefaultTimeFormat
func LastDayInMonthsAgo ¶ added in v1.0.5
func LastDayInMonthsAhead ¶ added in v1.0.5
func MustParseDate ¶ added in v1.0.4
MustParseDate is like ParseDate, but panics on error
func MustParseDateTime ¶ added in v1.0.4
MustParseDateTime is like ParseDateTime, but panics on error
func MustParseTime ¶ added in v1.0.4
MustParseTime is like ParseTime, but panics on error
func ParseDateTime ¶
Parse parses a date in DefaultDateTimeFormat to a date
Types ¶
type ParseError ¶ added in v1.0.3
func (ParseError) Error ¶ added in v1.0.3
func (p ParseError) Error() string