You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With current time pkg api, what is a good way to validate if a given input date is valid or not?
Suppose a scenario we have given three ints 2021, 02 and 29, for year,month,day and need to validate if it represents a valid date or not.
This can be achieved by writing a small helper function like
func isValidDate(year, month, day int) bool {
t := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC)
y, m, d := t.Date()
return y == year && m == time.Month(month) && d == day
}
amarjeetanandsingh
changed the title
proposal: time: a better way to validate if a time instance
proposal: time: a better way to validate a time instance
Feb 29, 2024
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
Proposal Details
With current
time
pkg api, what is a good way to validate if a given input date is valid or not?Suppose a scenario we have given three ints 2021, 02 and 29, for year,month,day and need to validate if it represents a valid date or not.
This can be achieved by writing a small helper function like
Or maybe another way could be -
What approach would u recommend for this? Or is this use case worthy enough to be added in the
time
pkg?The text was updated successfully, but these errors were encountered: