Added pretty printing for time.Time.
diff --git a/format/format.go b/format/format.go index 5cd89bc..fde341f 100644 --- a/format/format.go +++ b/format/format.go
@@ -40,6 +40,7 @@ } var contextType = reflect.TypeOf((*Ctx)(nil)).Elem() +var timeType = reflect.TypeOf(time.Time{}) //The default indentation string emitted by the format package var Indent = " " @@ -179,6 +180,10 @@ case reflect.Map: return formatMap(value, indentation) case reflect.Struct: + if value.Type() == timeType { + t, _ := value.Interface().(time.Time) + return t.Format(time.RFC3339Nano) + } return formatStruct(value, indentation) case reflect.Interface: return formatValue(value.Elem(), indentation)
diff --git a/format/format_test.go b/format/format_test.go index 4d4b36c..a27cea2 100644 --- a/format/format_test.go +++ b/format/format_test.go
@@ -380,6 +380,13 @@ Ω(Object(s, 1)).Should(matchRegexp(`format_test\.ComplexStruct`, expected)) }) }) + + Describe("formatting times", func() { + It("should format time as RFC3339", func() { + t := time.Date(2016, 10, 31, 9, 57, 23, 12345, time.UTC) + Ω(Object(t, 1)).Should(match("time.Time", `2016-10-31T09:57:23.000012345Z`)) + }) + }) }) Describe("Handling unexported fields in structs", func() {