diff --git a/github/timestamp.go b/github/timestamp.go index 1061a55e68e..00c1235e9d3 100644 --- a/github/timestamp.go +++ b/github/timestamp.go @@ -22,6 +22,14 @@ func (t Timestamp) String() string { return t.Time.String() } +// GetTime returns std time.Time. +func (t *Timestamp) GetTime() *time.Time { + if t == nil { + return nil + } + return &t.Time +} + // UnmarshalJSON implements the json.Unmarshaler interface. // Time is expected in RFC3339 or Unix format. func (t *Timestamp) UnmarshalJSON(data []byte) (err error) { diff --git a/github/timestamp_test.go b/github/timestamp_test.go index 097249519d4..69245b60d73 100644 --- a/github/timestamp_test.go +++ b/github/timestamp_test.go @@ -169,6 +169,17 @@ func TestWrappedTimestamp_Unmarshal(t *testing.T) { } } +func TestTimestamp_GetTime(t *testing.T) { + var t1 *Timestamp + if t1.GetTime() != nil { + t.Errorf("nil timestamp should return nil, got: %v", t1.GetTime()) + } + t1 = &Timestamp{referenceTime} + if !t1.GetTime().Equal(referenceTime) { + t.Errorf("want reference time, got: %s", t1.GetTime().String()) + } +} + func TestWrappedTimestamp_MarshalReflexivity(t *testing.T) { testCases := []struct { desc string