From 3686f2d50a796b0ce645d7c03c94a02e5d2f3106 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 8 Apr 2023 11:44:01 +0200 Subject: [PATCH 1/2] Add GetTime() to Timestamp --- github/timestamp.go | 8 ++++++++ github/timestamp_test.go | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/github/timestamp.go b/github/timestamp.go index 1061a55e68e..48abe0f92a1 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 From 8508610995d4787f30b27bd4bd124bdfc434f83c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 8 Apr 2023 14:11:14 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/timestamp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/timestamp.go b/github/timestamp.go index 48abe0f92a1..00c1235e9d3 100644 --- a/github/timestamp.go +++ b/github/timestamp.go @@ -22,7 +22,7 @@ func (t Timestamp) String() string { return t.Time.String() } -// GetTime returns std time.Time +// GetTime returns std time.Time. func (t *Timestamp) GetTime() *time.Time { if t == nil { return nil