Skip to content

Commit 521fd0d

Browse files
authored
Add GetTime method to Timestamp (#2743)
1 parent 4caa1d6 commit 521fd0d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

github/timestamp.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ func (t Timestamp) String() string {
2222
return t.Time.String()
2323
}
2424

25+
// GetTime returns std time.Time.
26+
func (t *Timestamp) GetTime() *time.Time {
27+
if t == nil {
28+
return nil
29+
}
30+
return &t.Time
31+
}
32+
2533
// UnmarshalJSON implements the json.Unmarshaler interface.
2634
// Time is expected in RFC3339 or Unix format.
2735
func (t *Timestamp) UnmarshalJSON(data []byte) (err error) {

github/timestamp_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ func TestWrappedTimestamp_Unmarshal(t *testing.T) {
169169
}
170170
}
171171

172+
func TestTimestamp_GetTime(t *testing.T) {
173+
var t1 *Timestamp
174+
if t1.GetTime() != nil {
175+
t.Errorf("nil timestamp should return nil, got: %v", t1.GetTime())
176+
}
177+
t1 = &Timestamp{referenceTime}
178+
if !t1.GetTime().Equal(referenceTime) {
179+
t.Errorf("want reference time, got: %s", t1.GetTime().String())
180+
}
181+
}
182+
172183
func TestWrappedTimestamp_MarshalReflexivity(t *testing.T) {
173184
testCases := []struct {
174185
desc string

0 commit comments

Comments
 (0)