Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetTime method to Timestamp #2743

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func (t Timestamp) String() string {
return t.Time.String()
}

// GetTime returns std time.Time
6543 marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down
11 changes: 11 additions & 0 deletions github/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down