-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: add UUID, date, and datetime helpers for terraform usage #96
Conversation
|
975aaa1
to
1e6c007
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the date/time conversion methods should have error returns and use the date-time conversion support we have already built into the core.
v5/core/utils.go
Outdated
|
||
// ParseDateTime parses and returns a strfmt DateTime pointer | ||
func ParseDateTime(dateString string) *strfmt.DateTime { | ||
formattedTime, _ := time.Parse(time.RFC3339, dateString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use strfmt.ParseDateTime
here. It has already been set up to handle all the date-time formats we need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use strfmt.ParseDateTime
with error handling!
v5/core/utils.go
Outdated
@@ -182,6 +188,20 @@ func GetCurrentTime() int64 { | |||
return time.Now().Unix() | |||
} | |||
|
|||
// ParseDate parses and returns a strfmt Date pointer | |||
func ParseDate(dateString string) *strfmt.Date { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should have an error return on this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with an error return! The generator PR was also update to catch this error return and use a variable name that wont run into redeclaration issues, new change here: https://github.ibm.com/CloudEngineering/openapi-sdkgen/pull/873/files#diff-9f83f4d9d6cba74e36a0c6fd148b83e9R936
v5/core/utils.go
Outdated
} | ||
|
||
// ParseDateTime parses and returns a strfmt DateTime pointer | ||
func ParseDateTime(dateString string) *strfmt.DateTime { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have an error return on this method.
1e6c007
to
936e78b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. Just had some minor comments. Also, I think it would be good to add at least one negative test for ParseDate() and ParseDateTime().
v5/core/utils_test.go
Outdated
dateVar := strfmt.Date(time.Now()) | ||
fmtDate, err := ParseDate(dateVar.String()) | ||
assert.Nil(t, err) | ||
assert.True(t, dateVar.String() == fmtDate.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.True(t, dateVar.String() == fmtDate.String()) | |
assert.Equal(t, dateVar.String(), fmtDate.String()) |
v5/core/utils_test.go
Outdated
var fmtDTime *strfmt.DateTime | ||
fmtDTime, err = ParseDateTime(dateTimeVar.String()) | ||
assert.Nil(t, err) | ||
assert.True(t, dateTimeVar.String() == fmtDTime.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.True(t, dateTimeVar.String() == fmtDTime.String()) | |
assert.Equal(t, dateTimeVar.String(), fmtDTime.String()) |
v5/core/utils.go
Outdated
@@ -182,6 +188,25 @@ func GetCurrentTime() int64 { | |||
return time.Now().Unix() | |||
} | |||
|
|||
// ParseDate parses and returns a strfmt Date pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ParseDate parses and returns a strfmt Date pointer | |
// ParseDate parses the specified RFC3339 full-date string (YYYY-MM-DD) and returns a strfmt.Date instance. |
v5/core/utils.go
Outdated
return &formattedDate, nil | ||
} | ||
|
||
// ParseDateTime parses and returns a strfmt DateTime pointer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// ParseDateTime parses and returns a strfmt DateTime pointer | |
// ParseDateTime parses the specified date-time string and returns a strfmt.DateTime instance. |
a47eb03
to
c805b87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good but I'd like a small change in the interface.
v5/core/utils.go
Outdated
} | ||
|
||
// ParseDateTime parses the specified date-time string and returns a strfmt.DateTime instance. | ||
func ParseDateTime(dateString string) (fmtDTime *strfmt.DateTime, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better for this method to return a strfmt.DateTime
rather than a pointer to strfmt.DateTime
. This is perhaps a question of style, and thus somewhat subjective, but in my defense I will note that strfmt.ParseDateTime
returns a strfmt.DateTime
.
v5/core/utils.go
Outdated
@@ -182,6 +188,25 @@ func GetCurrentTime() int64 { | |||
return time.Now().Unix() | |||
} | |||
|
|||
// ParseDate parses the specified RFC3339 full-date string (YYYY-MM-DD) and returns a strfmt.Date instance. | |||
func ParseDate(dateString string) (fmtDate *strfmt.Date, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also, I think we should return a strfmt.Date
rather than a pointer.
c805b87
to
271a2ea
Compare
271a2ea
to
7f4477e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
# [5.1.0](v5.0.3...v5.1.0) (2021-03-04) ### Features * add UUID, date, and datetime helpers for terraform usage ([#96](#96)) ([e651369](e651369))
🎉 This PR is included in version 5.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Add helper methods for casting strfmt UUID, Date, and DateTime literals to pointers needed by the go setter methods. Also, this is only parsing dates with RFC3339. This likely needs to be updated in the future to allow other formats to be used.
This is used in the sdk generator PR #873