-
Notifications
You must be signed in to change notification settings - Fork 4
PHPLIB-1350 PHPLIB-1350 Add tests on Date Expression Operators and add Yaml tags for BSON types #34
Conversation
dateString: '$date' | ||
timezone: '$timezone' | ||
# onNull: new Date(0) | ||
onNull: 1970-01-01T00:00:00+00:00 |
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.
I tried to represent the date using the Extended JSON format: { $date: 0 }
, but this get converted to { $date: { $numberInt: 0 } }
and the date is actually represented with a long { $date: { $numberLong: 0 } }
.
So I ended using Yaml date, that why I configured the parser to parse dates, and added a transformation pass using array_walk_recursive
to convert DateTimeInterface
into MongoDB\BSON\UTCDateTime
.
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.
Just adding a note that we can leverage a custom tag for this if we run into issues with the automatic parsing of dates when we don't expect it: https://symfony.com/doc/current/components/yaml.html#parsing-and-dumping-custom-tags
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.
I switched all specific BSON types to Yaml tags. That's more explicit.
day: | ||
# $dayOfMonth: '$date' | ||
$dayOfMonth: | ||
date: '$date' |
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.
The example is the same for all this date part operators. So I picked only the tested operator for each.
Stage::project( | ||
expectedDeliveryDate: Expression::dateAdd( | ||
startDate: Expression::dateFieldPath('purchaseDate'), | ||
unit: 'day', |
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.
It would be very useful to have an enum for this units. PHPLIB-1370
unit: 'day' | ||
amount: 3 | ||
- | ||
# $merge: 'shipping' |
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.
Noted you left a comment denoting the original since our $merge
operator always uses the into
argument.
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.
I did this in few other place. So that if we find there is a bug, it's easier to see the original example.
$pipeline = $test->pipeline; | ||
array_walk_recursive($pipeline, function (mixed &$value): void { | ||
if ($value instanceof DateTimeInterface) { | ||
$value = new UTCDateTime($value); | ||
} | ||
}); |
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.
This looks like it's left over from before extracting convertTypeRecursively
.
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.
Removed, thanks.
dateString: '$date' | ||
timezone: '$timezone' | ||
# onNull: new Date(0) | ||
onNull: 1970-01-01T00:00:00+00:00 |
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.
Just adding a note that we can leverage a custom tag for this if we run into issues with the automatic parsing of dates when we don't expect it: https://symfony.com/doc/current/components/yaml.html#parsing-and-dumping-custom-tags
76fb890
to
2cb9464
Compare
Added support for |
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.
Yaml tags look a lot better, great work!
Fix PHPLIB-1350
https://www.mongodb.com/docs/manual/reference/operator/aggregation/#date-expression-operators
$dateAdd
$dateDiff
$dateFromParts
$dateFromString
$dateSubtract
$dateToParts
$dateToString
$dateTrunc
$dayOfMonth
using verbosedate
field$dayOfWeek
using verbosedate
field$dayOfYear
using verbosedate
field$hour
using verbosedate
field$isoDayOfWeek
using verbosedate
field$isoWeek
using verbosedate
field$isoWeekYear
using verbosedate
field$millisecond
using verbosedate
field$minute
using verbosedate
field$month
using verbosedate
field$second
using verbosedate
field$toDate
$week
using verbosedate
field$year
using verbosedate
field