7
// Time defines a type similar to time.Time but assumes a layout of RFC3339 date-time (i.e.,
8
// 2006-01-02T15:04:05Z).
13
// ParseTime creates a new Time from the passed string.
14
func ParseTime(date string) (d Time, err error) {
16
d.Time, err = time.Parse(time.RFC3339, date)
20
// MarshalBinary preserves the Time as a byte array conforming to RFC3339 date-time (i.e.,
21
// 2006-01-02T15:04:05Z).
22
func (d Time) MarshalBinary() ([]byte, error) {
23
return d.Time.MarshalText()
26
// UnmarshalBinary reconstitutes a Time saved as a byte array conforming to RFC3339 date-time
27
// (i.e., 2006-01-02T15:04:05Z).
28
func (d *Time) UnmarshalBinary(data []byte) error {
29
return d.Time.UnmarshalText(data)
32
// MarshalJSON preserves the Time as a JSON string conforming to RFC3339 date-time (i.e.,
33
// 2006-01-02T15:04:05Z).
34
func (d Time) MarshalJSON() (json []byte, err error) {
35
return d.Time.MarshalJSON()
38
// UnmarshalJSON reconstitutes the Time from a JSON string conforming to RFC3339 date-time
39
// (i.e., 2006-01-02T15:04:05Z).
40
func (d *Time) UnmarshalJSON(data []byte) (err error) {
41
return d.Time.UnmarshalJSON(data)
44
// MarshalText preserves the Time as a byte array conforming to RFC3339 date-time (i.e.,
45
// 2006-01-02T15:04:05Z).
46
func (d Time) MarshalText() (text []byte, err error) {
47
return d.Time.MarshalText()
50
// UnmarshalText reconstitutes a Time saved as a byte array conforming to RFC3339 date-time
51
// (i.e., 2006-01-02T15:04:05Z).
52
func (d *Time) UnmarshalText(data []byte) (err error) {
53
return d.Time.UnmarshalText(data)
56
// String returns the Time formatted as an RFC3339 date-time string (i.e.,
57
// 2006-01-02T15:04:05Z).
58
func (d Time) String() string {
59
// Note: time.Time.String does not return an RFC3339 compliant string, time.Time.MarshalText does.
60
b, err := d.Time.MarshalText()
67
// ToTime returns a Time as a time.Time
68
func (d Time) ToTime() time.Time {