Closed bg451 closed 1 year ago
cc @casualjim
Merging #105 (397e96b) into master (a239ff1) will increase coverage by
0.03%
. The diff coverage is100.00%
.
@@ 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
Impacted Files | Coverage Δ | |
---|---|---|
time.go | 90.97% <100.00%> (+0.25%) |
:arrow_up: |
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 time.Unix(0,0)
to be zero. Go's idea of a mindate is different from other languages.
This seems to be the pattern for it: https://github.com/golang/go/issues/33597#issuecomment-548232450
This could also use a companion method that considers time.Unix(0,0) to be zero.
@casualjim Hm so turns out this behavior isn't as simple as you'd hope. The equivalency is timezone dependent, e.g. time.Unix(0, 0)
!= time.Unix(0, 0).UTC()
on my laptop. When the locale is UTC, the equivalency check is fine, but this seems pretty prone to cause bugs to due the nuance of it.
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
@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.