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

DateTaime.IsZero() should support pointer receiver #106

Closed
pavel-boldyrev-form3 opened this issue Mar 27, 2023 · 1 comment
Closed

DateTaime.IsZero() should support pointer receiver #106

pavel-boldyrev-form3 opened this issue Mar 27, 2023 · 1 comment

Comments

@pavel-boldyrev-form3
Copy link

I think this is a regression after #105, particularly this line:

func (t DateTime) IsZero() bool {
	return time.Time(t).IsZero()
}

I think IsZero() func should accept a pointer receiver, as it may be called on nil values.

For example, I have a generated code from a swagger model that does the following check on an optional date-time field created_on in the request:

func (m *Entity) validateCreatedOn(formats strfmt.Registry) error {
	if swag.IsZero(m.CreatedOn) { // not required
		return nil
	}

	if err := validate.FormatOf("created_on", "body", "date-time", m.CreatedOn.String(), formats); err != nil {
		return err
	}

	return nil
}

which now panics on the very first if statement.

@piepmatz
Copy link

Alternative: go-openapi/swag#67

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

No branches or pull requests

2 participants