diff --git a/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt index 6ad2fdbe..a77bae82 100644 --- a/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt @@ -137,6 +137,7 @@ import opensavvy.ktmongo.dsl.query.FilterQuery * - [`$toUUID`][TypeValueOperators.toUuid] * * Date and time operators: + * - [`$minute`][DateTimeValueOperators.minute] * - [`$month`][DateTimeValueOperators.month] * - [`$second`][DateTimeValueOperators.second] * - [`$week`][DateTimeValueOperators.week] diff --git a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt index e76fca84..ee4a1acd 100644 --- a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -420,6 +420,100 @@ interface DateTimeValueOperators : ValueOperators { final val Value.month: Value get() = UnaryOperator(context, "month", this) + // endregion + // region $minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + val Value.minute: Value + get() = UnaryOperator(context, "minute", this) + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfObjectId") + final val Value.minute: Value + get() = UnaryOperator(context, "minute", this) + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfTimestamp") + final val Value.minute: Value + get() = UnaryOperator(context, "minute", this) + // endregion @LowLevelApi diff --git a/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt index f1891ca0..100350af 100644 --- a/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt +++ b/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt @@ -140,6 +140,7 @@ import opensavvy.ktmongo.dsl.query.FilterQuery * - [`$toUUID`][TypeValueOperators.toUuid] * * Date and time operators: + * - [`$minute`][DateTimeValueOperators.minute] * - [`$month`][DateTimeValueOperators.month] * - [`$second`][DateTimeValueOperators.second] * - [`$week`][DateTimeValueOperators.week] diff --git a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt index c9a07acb..2260b0d6 100644 --- a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -1558,6 +1558,377 @@ interface DateTimeValueOperators : ValueOperators { final val Timestamp.month: Value get() = of(this).month + // endregion + // region $minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + val Value.minute: Value + get() = UnaryOperator(context, "minute", this) + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + val opensavvy.ktmongo.dsl.path.Field.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + val kotlin.reflect.KProperty1.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @Suppress("INVISIBLE_REFERENCE") + @OptIn(LowLevelApi::class) + val Instant.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfObjectId") + final val Value.minute: Value + get() = UnaryOperator(context, "minute", this) + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfObjectId") + final val opensavvy.ktmongo.dsl.path.Field.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfObjectId") + final val kotlin.reflect.KProperty1.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfObjectId") + final val ObjectId.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfTimestamp") + final val Value.minute: Value + get() = UnaryOperator(context, "minute", this) + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfTimestamp") + final val opensavvy.ktmongo.dsl.path.Field.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfTimestamp") + final val kotlin.reflect.KProperty1.minute: Value + get() = of(this).minute + + /** + * Returns the minute portion of a date as a number between `0` and `59`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthminute: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthminute set User::birthdate.minute + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("minuteOfTimestamp") + final val Timestamp.minute: Value + get() = of(this).minute + // endregion @LowLevelApi diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt index 1f9d6467..182fe416 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt @@ -29,6 +29,7 @@ val DateTimeValueOperatorsTest by multiContextSuite { val week: Int, val second: Int, val month: Int, + val minute: Int, ) test($$"$year") { @@ -103,4 +104,22 @@ val DateTimeValueOperatorsTest by multiContextSuite { """.trimIndent()) } + test($$"$minute") { + TestPipeline() + .set { + Target::minute set Target::date.minute + } + .shouldBeBson($$""" + [ + { + "$set": { + "minute": { + "$minute": "$date" + } + } + } + ] + """.trimIndent()) + } + }