diff --git a/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt --- a/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt @@ -139,6 +139,7 @@ * Date and time operators: * - [`$dayOfMonth`][DateTimeValueOperators.dayOfMonth] * - [`$dayOfWeek`][DateTimeValueOperators.dayOfWeek] + * - [`$dayOfYear`][DateTimeValueOperators.dayOfYear] * - [`$hour`][DateTimeValueOperators.hour] * - [`$isoDayOfWeek`][DateTimeValueOperators.dayOfWeekIso] * - [`$isoWeek`][DateTimeValueOperators.weekIso] diff --git a/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt --- a/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt +++ b/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt @@ -142,6 +142,7 @@ * Date and time operators: * - [`$dayOfMonth`][DateTimeValueOperators.dayOfMonth] * - [`$dayOfWeek`][DateTimeValueOperators.dayOfWeek] + * - [`$dayOfYear`][DateTimeValueOperators.dayOfYear] * - [`$hour`][DateTimeValueOperators.hour] * - [`$isoDayOfWeek`][DateTimeValueOperators.dayOfWeekIso] * - [`$isoWeek`][DateTimeValueOperators.weekIso] diff --git a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt --- a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -1210,6 +1210,107 @@ // endregion + // region $dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + val Value.dayOfYear: Value + get() = UnaryOperator(context, "dayOfYear", this) + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfObjectId") + final val Value.dayOfYear: Value + get() = UnaryOperator(context, "dayOfYear", this) + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfTimestamp") + final val Value.dayOfYear: Value + get() = UnaryOperator(context, "dayOfYear", this) + + // endregion + @LowLevelApi private class UnaryOperator( context: BsonContext, diff --git a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt --- a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -4672,6 +4672,402 @@ // endregion + // region $dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + val Value.dayOfYear: Value + get() = UnaryOperator(context, "dayOfYear", this) + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + val opensavvy.ktmongo.dsl.path.Field.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + val kotlin.reflect.KProperty1.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @Suppress("INVISIBLE_REFERENCE") + @OptIn(LowLevelApi::class) + val Instant.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfObjectId") + final val Value.dayOfYear: Value + get() = UnaryOperator(context, "dayOfYear", this) + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfObjectId") + final val opensavvy.ktmongo.dsl.path.Field.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfObjectId") + final val kotlin.reflect.KProperty1.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfObjectId") + final val ObjectId.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfTimestamp") + final val Value.dayOfYear: Value + get() = UnaryOperator(context, "dayOfYear", this) + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfTimestamp") + final val opensavvy.ktmongo.dsl.path.Field.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfTimestamp") + final val kotlin.reflect.KProperty1.dayOfYear: Value + get() = of(this).dayOfYear + + /** + * Returns the day of the year for a date as a number between `1` and `366`. + * + * The year starts on January 1st, so January 1st is day `1`, and December 31st is day `365` (or `366` in a leap year). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthdayOfYear: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthdayOfYear set User::birthdate.dayOfYear + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("dayOfYearOfTimestamp") + final val Timestamp.dayOfYear: Value + get() = of(this).dayOfYear + + // endregion + @LowLevelApi private class UnaryOperator( context: BsonContext, diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt --- a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt @@ -37,6 +37,7 @@ val hour: Int, val dayOfMonth: Int, val dayOfWeek: Int, + val dayOfYear: Int, ) test($$"$year") { @@ -248,6 +249,24 @@ "$set": { "dayOfWeek": { "$dayOfWeek": "$date" + } + } + } + ] + """.trimIndent()) + } + + test($$"$dayOfYear") { + TestPipeline() + .set { + Target::dayOfYear set Target::date.dayOfYear + } + .shouldBeBson($$""" + [ + { + "$set": { + "dayOfYear": { + "$dayOfYear": "$date" } } }