improve package gtime for nil gtime.Time object
@@ -131,27 +131,42 @@ func (t *Time) Format(format string) string {
// FormatNew formats and returns a new Time object with given custom <format>.
func (t *Time) FormatNew(format string) *Time {
+ if t == nil {
+ return nil
+ }
return NewFromStr(t.Format(format))
}
// FormatTo formats <t> with given custom <format>.
func (t *Time) FormatTo(format string) *Time {
+ if t == nil {
+ return nil
+ }
t.Time = NewFromStr(t.Format(format)).Time
return t
}
// Layout formats the time with stdlib layout and returns the formatted result.
func (t *Time) Layout(layout string) string {
+ if t == nil {
+ return ""
+ }
return t.Time.Format(layout)
}
// LayoutNew formats the time with stdlib layout and returns the new Time object.
func (t *Time) LayoutNew(layout string) *Time {
+ if t == nil {
+ return nil
+ }
return NewFromStr(t.Layout(layout))
}
// LayoutTo formats <t> with stdlib layout.
func (t *Time) LayoutTo(layout string) *Time {
+ if t == nil {
+ return nil
+ }
t.Time = NewFromStr(t.Layout(layout)).Time
return t
}
