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

feat: add UUID, date, and datetime helpers for terraform usage #96

Merged
merged 2 commits into from
Mar 4, 2021

Conversation

rmkeezer
Copy link
Contributor

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

@CLAassistant
Copy link

CLAassistant commented Feb 22, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ padamstx
❌ rmkeezer
You have signed the CLA already but the status is still pending? Let us recheck it.

@rmkeezer rmkeezer force-pushed the add_uuid_date_helper branch 2 times, most recently from 975aaa1 to 1e6c007 Compare February 22, 2021 17:19
Copy link
Contributor

@mkistler mkistler left a 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)
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

@rmkeezer rmkeezer Feb 23, 2021

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 {
Copy link
Contributor

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.

Copy link
Member

@padamstx padamstx left a 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().

dateVar := strfmt.Date(time.Now())
fmtDate, err := ParseDate(dateVar.String())
assert.Nil(t, err)
assert.True(t, dateVar.String() == fmtDate.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.True(t, dateVar.String() == fmtDate.String())
assert.Equal(t, dateVar.String(), fmtDate.String())

var fmtDTime *strfmt.DateTime
fmtDTime, err = ParseDateTime(dateTimeVar.String())
assert.Nil(t, err)
assert.True(t, dateTimeVar.String() == fmtDTime.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ParseDateTime parses and returns a strfmt DateTime pointer
// ParseDateTime parses the specified date-time string and returns a strfmt.DateTime instance.

@rmkeezer rmkeezer force-pushed the add_uuid_date_helper branch 3 times, most recently from a47eb03 to c805b87 Compare March 2, 2021 11:15
@rmkeezer rmkeezer requested a review from padamstx March 2, 2021 15:26
Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@mkistler mkistler left a 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) {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

@mkistler mkistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@padamstx padamstx merged commit e651369 into main Mar 4, 2021
@padamstx padamstx deleted the add_uuid_date_helper branch March 4, 2021 19:56
ibm-devx-automation pushed a commit that referenced this pull request Mar 4, 2021
# [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))
@ibm-devx-automation
Copy link

🎉 This PR is included in version 5.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants