-
Notifications
You must be signed in to change notification settings - Fork 388
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
Support $currentDate
field update operator
#662
Support $currentDate
field update operator
#662
Conversation
Codecov Report
@@ Coverage Diff @@
## main #662 +/- ##
==========================================
+ Coverage 63.85% 64.21% +0.36%
==========================================
Files 192 193 +1
Lines 7694 7814 +120
==========================================
+ Hits 4913 5018 +105
- Misses 2225 2233 +8
- Partials 556 563 +7
Flags with carried forward coverage won't be shown. Click here to find out more. |
I invite you not to review but to discuss. |
@w84thesun @rumyantseva PTAL, I've changed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
fb8b9d6 commit body is empty |
testutil.CompareAndSetByPathTime( | ||
t, | ||
expected, | ||
actual, | ||
maxDifference, | ||
path, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those arguments are short enough to be put on the same line
expected.RemoveByPath(path) | ||
actual.RemoveByPath(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do we set values by path only to remove them on the next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do we set values by path only to remove them on the next line?
There is assert.Equal(t, expected, actual)
below, and it tests whether other document values are ok (not changed, not removed, not updated anyhow).
t.Parallel() | ||
|
||
// maxDifference is a maximum amount of seconds can differ the value in placeholder from actual value | ||
maxDifference := time.Duration(60 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That values should be that large. We are in a serious trouble if that test runs for 60 seconds
now := primitive.NewDateTimeFromTime(time.Now().UTC()) | ||
nowTimestamp := primitive.Timestamp{T: uint32(time.Now().UTC().Unix()), I: uint32(0)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there
assert.WithinDuration(tb, expectedT, actualT, delta) | ||
|
||
default: | ||
tb.FailNow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a better error message there
} | ||
|
||
// DateTime returns time.Time ignoring increment. | ||
func DateTime(t Timestamp) time.Time { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it a method: func (t Timestamp) Time() time.Time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it a method:
func (t Timestamp) Time() time.Time
beautiful ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it a method:
func (t Timestamp) Time() time.Time
changed.
// DateTime returns time.Time ignoring increment. | ||
func DateTime(t Timestamp) time.Time { | ||
t >>= 32 | ||
return time.UnixMilli(int64(t)).UTC() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there
changed.
func NextTimestamp(t time.Time) Timestamp { | ||
sec := t.UTC().Unix() | ||
c := atomic.AddUint32(×tampCounter, 1) | ||
sec <<= 32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we could just call NewTimestamp(t, c)
there to avoid copying the same code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we could just call
NewTimestamp(t, c)
there to avoid copying the same code
amazing.
|
||
// NewTimestamp returns a timestamp from time and an increment. | ||
func NewTimestamp(t time.Time, c uint32) Timestamp { | ||
sec := t.UTC().Unix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there. Unix timestamps are always in UTC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there. Unix timestamps are always in UTC
changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func NextTimestamp(t time.Time) Timestamp { | ||
sec := t.UTC().Unix() | ||
c := atomic.AddUint32(×tampCounter, 1) | ||
sec <<= 32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we could just call
NewTimestamp(t, c)
there to avoid copying the same code
amazing.
|
||
// NewTimestamp returns a timestamp from time and an increment. | ||
func NewTimestamp(t time.Time, c uint32) Timestamp { | ||
sec := t.UTC().Unix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there. Unix timestamps are always in UTC
changed.
} | ||
|
||
// DateTime returns time.Time ignoring increment. | ||
func DateTime(t Timestamp) time.Time { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it a method:
func (t Timestamp) Time() time.Time
beautiful ❤️
// DateTime returns time.Time ignoring increment. | ||
func DateTime(t Timestamp) time.Time { | ||
t >>= 32 | ||
return time.UnixMilli(int64(t)).UTC() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.UTC()
does nothing there
changed.
} | ||
|
||
// DateTime returns time.Time ignoring increment. | ||
func DateTime(t Timestamp) time.Time { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it a method:
func (t Timestamp) Time() time.Time
changed.
Closes #622.