|
|
@@ -88,148 +88,136 @@ type datetimePatternComponent struct {
|
|
|
|
|
|
// FmtDateFull formats the time with the current locales full date format
|
|
|
func (c Calendar) FmtDateFull(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Date.Full)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Date.Full)
|
|
|
}
|
|
|
|
|
|
// FmtDateLong formats the time with the current locales long date format
|
|
|
func (c Calendar) FmtDateLong(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Date.Long)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Date.Long)
|
|
|
}
|
|
|
|
|
|
// FmtDateMedium formats the time with the current locales medium date format
|
|
|
func (c Calendar) FmtDateMedium(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Date.Medium)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Date.Medium)
|
|
|
}
|
|
|
|
|
|
// FmtDateShort formats the time with the current locales short date format
|
|
|
func (c Calendar) FmtDateShort(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Date.Short)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Date.Short)
|
|
|
}
|
|
|
|
|
|
// FmtTimeFull formats the time with the current locales full time format
|
|
|
func (c Calendar) FmtTimeFull(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Time.Full)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Time.Full)
|
|
|
}
|
|
|
|
|
|
// FmtTimeLong formats the time with the current locales long time format
|
|
|
func (c Calendar) FmtTimeLong(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Time.Long)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Time.Long)
|
|
|
}
|
|
|
|
|
|
// FmtTimeMedium formats the time with the current locales medium time format
|
|
|
func (c Calendar) FmtTimeMedium(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Time.Medium)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Time.Medium)
|
|
|
}
|
|
|
|
|
|
// FmtTimeShort formats the time with the current locales short time format
|
|
|
func (c Calendar) FmtTimeShort(t time.Time) string {
|
|
|
- s, _ := c.Format(t, c.Formats.Time.Short)
|
|
|
- return s
|
|
|
+ return c.Format(t, c.Formats.Time.Short)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeFull formats the time with the current locales full data & time format
|
|
|
func (c Calendar) FmtDateTimeFull(t time.Time) string {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Full, c.Formats.Date.Full, c.Formats.Time.Full)
|
|
|
- s, _ := c.Format(t, pattern)
|
|
|
- return s
|
|
|
+ return c.Format(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeLong formats the time with the current locales long data & time format
|
|
|
func (c Calendar) FmtDateTimeLong(t time.Time) string {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Long, c.Formats.Date.Long, c.Formats.Time.Long)
|
|
|
- s, _ := c.Format(t, pattern)
|
|
|
- return s
|
|
|
+ return c.Format(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeMedium formats the time with the current locales medium data & time format
|
|
|
func (c Calendar) FmtDateTimeMedium(t time.Time) string {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Medium, c.Formats.Date.Medium, c.Formats.Time.Medium)
|
|
|
- s, _ := c.Format(t, pattern)
|
|
|
- return s
|
|
|
+ return c.Format(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeShort formats the time with the current locales short data & time format
|
|
|
func (c Calendar) FmtDateTimeShort(t time.Time) string {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Short, c.Formats.Date.Short, c.Formats.Time.Short)
|
|
|
- s, _ := c.Format(t, pattern)
|
|
|
- return s
|
|
|
+ return c.Format(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateFullSafe formats the time with the current locales full date format
|
|
|
func (c Calendar) FmtDateFullSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Date.Full)
|
|
|
+ return c.FormatSafe(t, c.Formats.Date.Full)
|
|
|
}
|
|
|
|
|
|
// FmtDateLongSafe formats the time with the current locales long date format
|
|
|
func (c Calendar) FmtDateLongSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Date.Long)
|
|
|
+ return c.FormatSafe(t, c.Formats.Date.Long)
|
|
|
}
|
|
|
|
|
|
// FmtDateMediumSafe formats the time with the current locales medium date format
|
|
|
func (c Calendar) FmtDateMediumSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Date.Medium)
|
|
|
+ return c.FormatSafe(t, c.Formats.Date.Medium)
|
|
|
}
|
|
|
|
|
|
// FmtDateShortSafe formats the time with the current locales short date format
|
|
|
func (c Calendar) FmtDateShortSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Date.Short)
|
|
|
+ return c.FormatSafe(t, c.Formats.Date.Short)
|
|
|
}
|
|
|
|
|
|
// FmtTimeFullSafe formats the time with the current locales full time format
|
|
|
func (c Calendar) FmtTimeFullSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Time.Full)
|
|
|
+ return c.FormatSafe(t, c.Formats.Time.Full)
|
|
|
}
|
|
|
|
|
|
// FmtTimeLongSafe formats the time with the current locales long time format
|
|
|
func (c Calendar) FmtTimeLongSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Time.Long)
|
|
|
+ return c.FormatSafe(t, c.Formats.Time.Long)
|
|
|
}
|
|
|
|
|
|
// FmtTimeMediumSafe formats the time with the current locales medium time format
|
|
|
func (c Calendar) FmtTimeMediumSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Time.Medium)
|
|
|
+ return c.FormatSafe(t, c.Formats.Time.Medium)
|
|
|
}
|
|
|
|
|
|
// FmtTimeShortSafe formats the time with the current locales short time format
|
|
|
func (c Calendar) FmtTimeShortSafe(t time.Time) (string, error) {
|
|
|
- return c.Format(t, c.Formats.Time.Short)
|
|
|
+ return c.FormatSafe(t, c.Formats.Time.Short)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeFullSafe formats the time with the current locales full data & time format
|
|
|
func (c Calendar) FmtDateTimeFullSafe(t time.Time) (string, error) {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Full, c.Formats.Date.Full, c.Formats.Time.Full)
|
|
|
- return c.Format(t, pattern)
|
|
|
+ return c.FormatSafe(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeLongSafe formats the time with the current locales long data & time format
|
|
|
func (c Calendar) FmtDateTimeLongSafe(t time.Time) (string, error) {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Long, c.Formats.Date.Long, c.Formats.Time.Long)
|
|
|
- return c.Format(t, pattern)
|
|
|
+ return c.FormatSafe(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeMediumSafe formats the time with the current locales medium data & time format
|
|
|
func (c Calendar) FmtDateTimeMediumSafe(t time.Time) (string, error) {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Medium, c.Formats.Date.Medium, c.Formats.Time.Medium)
|
|
|
- return c.Format(t, pattern)
|
|
|
+ return c.FormatSafe(t, pattern)
|
|
|
}
|
|
|
|
|
|
// FmtDateTimeShortSafe formats the time with the current locales short data & time format
|
|
|
func (c Calendar) FmtDateTimeShortSafe(t time.Time) (string, error) {
|
|
|
pattern := getDateTimePattern(c.Formats.DateTime.Short, c.Formats.Date.Short, c.Formats.Time.Short)
|
|
|
- return c.Format(t, pattern)
|
|
|
+ return c.FormatSafe(t, pattern)
|
|
|
}
|
|
|
|
|
|
-// Format takes a time struct and a format and returns a formatted
|
|
|
+// FormatSafe takes a time struct and a format and returns a formatted
|
|
|
// string. Callers should use a DateFormat, TimeFormat, or DateTimeFormat
|
|
|
// constant.
|
|
|
-func (c Calendar) Format(datetime time.Time, pattern string) (string, error) {
|
|
|
+func (c Calendar) FormatSafe(datetime time.Time, pattern string) (string, error) {
|
|
|
parsed, err := c.parseDateTimeFormat(pattern)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
@@ -238,6 +226,20 @@ func (c Calendar) Format(datetime time.Time, pattern string) (string, error) {
|
|
|
return c.formatDateTime(datetime, parsed)
|
|
|
}
|
|
|
|
|
|
+// Format takes a time struct and a format and returns a formatted
|
|
|
+// string. Callers should use a DateFormat, TimeFormat, or DateTimeFormat
|
|
|
+// constant.
|
|
|
+// NOTE: this function returns blank when an error occurs
|
|
|
+func (c Calendar) Format(datetime time.Time, pattern string) string {
|
|
|
+
|
|
|
+ dt, err := c.FormatSafe(datetime, pattern)
|
|
|
+ if err != nil {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ return dt
|
|
|
+}
|
|
|
+
|
|
|
// formatDateTime takes a time.Time and a sequence of parsed pattern components
|
|
|
// and returns an internationalized string representation.
|
|
|
func (c Calendar) formatDateTime(datetime time.Time, pattern []*datetimePatternComponent) (string, error) {
|