GODRIVER-3986: Implement date and timestamp expression operators and tests#15
Conversation
|
|
||
| // Year returns the year for a date ($year). | ||
| // date may resolve to a Date, Timestamp, or ObjectID. | ||
| func Year(date Expr, opts ...Option[datePartOptions]) NumberExpr { |
There was a problem hiding this comment.
The date param should use a type constraint that aligns with the described valid values. We should add something like ObjectIDResolver because the MQL spec for operators like $year describe a resolvesToObjectId.
This suggestion applies to all operator functions added in this PR that can accept a date param with the same valid types.
E.g.
type ObjectIDResolver interface {
AnyExpr | bson.ObjectID | string
}
func Year[T DateResolver | TimestampResolver | ObjectIDResolver](date T, opts ...Option[datePartOptions])There was a problem hiding this comment.
The ToObjectId operator function currently returns AnyExpr, but the spec says it should return resolvesToObjectId (our equivalent of ObjectIdExpr). Do you think we should create type ObjectIdExpr for it to return, or should it return bson.ObjectID?
There's also a CreateObjectId operator function in the next PR that this decision would apply to.
| return byte(typ), b, err | ||
| } | ||
|
|
||
| type TimestampExpr struct { |
There was a problem hiding this comment.
Are there any operators that return a TimestampExpr (i.e. return resolvesToTimestamp in the MQL spec)? If not, we should remove TimestampExpr since it won't be used.
…dd ObjectIdResolver.
GODRIVER-3986
Implements the types DateResolver, TimestampResolver, DateExpr, and TimestampExpr.
Implements the following operators and their corresponding tests: $dateAdd, $dateSubtract, $dateDiff, $dateFromParts, $dateFromString, $dateToParts, $dateToString, $dateTrunc, $dayOfMonth, $dayOfWeek, $dayOfYear, $hour, $isoDayOfWeek, $isoWeek, $isoWeekYear, $millisecond, $minute, $month, $second, $week, $year, $toDate, $tsIncrement, $tsSecond