From a8437a4db42a2d30b2baf8d8f891a3a1518276e2 Mon Sep 17 00:00:00 2001 From: Ivan “CLOVIS” Canet Date: Sat, 08 Aug 2026 11:10:18 +0000 Subject: [PATCH] feat(dsl): Add $minute (aggregation) --- dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt | 1 + dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt | 1 + dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt | 371 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt | 19 +++++++++++++++++++ 5 file(s) changed, 486 insertion(s)(+), 0 deletion(s)(-) 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 @@ -137,6 +137,7 @@ * - [`$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/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 @@ -140,6 +140,7 @@ * - [`$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 --- a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -421,6 +421,100 @@ 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 private class UnaryOperator( 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 @@ -1559,6 +1559,377 @@ 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 private class UnaryOperator( 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 @@ -29,6 +29,7 @@ val week: Int, val second: Int, val month: Int, + val minute: Int, ) test($$"$year") { @@ -96,6 +97,24 @@ "$set": { "month": { "$month": "$date" + } + } + } + ] + """.trimIndent()) + } + + test($$"$minute") { + TestPipeline() + .set { + Target::minute set Target::date.minute + } + .shouldBeBson($$""" + [ + { + "$set": { + "minute": { + "$minute": "$date" } } } -- tangled.sh