-
Notifications
You must be signed in to change notification settings - Fork 63
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
Adds IsZero functionality to DateTime #105
Conversation
a955e83
to
d203a72
Compare
cc @casualjim |
Codecov Report
@@ Coverage Diff @@
## master #105 +/- ##
==========================================
+ Coverage 81.52% 81.56% +0.03%
==========================================
Files 12 12
Lines 2019 2023 +4
==========================================
+ Hits 1646 1650 +4
Misses 295 295
Partials 78 78
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This could also use a companion method that considers This seems to be the pattern for it: golang/go#33597 (comment) |
@casualjim Hm so turns out this behavior isn't as simple as you'd hope. The equivalency is timezone dependent, e.g. |
We can do something like a package level method that captures the IsZero predicate. Similar to these vars: https://github.com/go-openapi/strfmt/blob/master/time.go#L83-L88 I think this should be configurable because if you are dealing with javascript or java clients and they send a min date, they should be able to determine what is the Zero date for their deployment |
This PR adds a new function `IsZero` to the DateTime struct. The goal of this is to satisfy a common interface, IsZeroer, used by go-yaml/yaml marshaller. `IsZero` already exists on the time.Time object, so this does not introduce any novel implementation. For reference, here is the [documentation note](https://pkg.go.dev/gopkg.in/yaml.v3#Marshal) on using IsZero by the `(yaml).Marshal` function. Signed-off-by: Brandon Gonzalez <bg@chronosphere.io>
Signed-off-by: Brandon Gonzalez <bg@chronosphere.io>
1404f67
to
397e96b
Compare
@casualjim alrighty, updated |
This PR adds a new function
IsZero
to the DateTime struct. The goal of this is to satisfy a common interface, IsZeroer, used by go-yaml/yaml marshaller.IsZero
already exists on the time.Time object, so this does not introduce any novel implementation.For reference, here is the documentation
note on using IsZero by the
(yaml).Marshal
function. If you have a struct generated by swagger that use a proto timestamp, a strfmt.DateTime is used. When you try to marshal this to yaml, all DateTime fields are skipped and excluded.