diff --git a/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt index dfcfb22d..f7fe29a9 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: + * - [`$second`][DateTimeValueOperators.second] * - [`$week`][DateTimeValueOperators.week] * - [`$year`][DateTimeValueOperators.year] * diff --git a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt index 3fe7671d..1be8ef80 100644 --- a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -232,6 +232,100 @@ interface DateTimeValueOperators : ValueOperators { final val Value.week: Value get() = UnaryOperator(context, "week", this) + // endregion + // region $second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + val Value.second: Value + get() = UnaryOperator(context, "second", this) + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfObjectId") + final val Value.second: Value + get() = UnaryOperator(context, "second", this) + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfTimestamp") + final val Value.second: Value + get() = UnaryOperator(context, "second", this) + // endregion @LowLevelApi diff --git a/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt index 3aa52b6e..bd07e9fd 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: + * - [`$second`][DateTimeValueOperators.second] * - [`$week`][DateTimeValueOperators.week] * - [`$year`][DateTimeValueOperators.year] * diff --git a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt index 16e662bf..817372e7 100644 --- a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -816,6 +816,377 @@ interface DateTimeValueOperators : ValueOperators { final val Timestamp.week: Value get() = of(this).week + // endregion + // region $second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + val Value.second: Value + get() = UnaryOperator(context, "second", this) + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + val opensavvy.ktmongo.dsl.path.Field.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + val kotlin.reflect.KProperty1.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @Suppress("INVISIBLE_REFERENCE") + @OptIn(LowLevelApi::class) + val Instant.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfObjectId") + final val Value.second: Value + get() = UnaryOperator(context, "second", this) + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfObjectId") + final val opensavvy.ktmongo.dsl.path.Field.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfObjectId") + final val kotlin.reflect.KProperty1.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfObjectId") + final val ObjectId.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfTimestamp") + final val Value.second: Value + get() = UnaryOperator(context, "second", this) + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfTimestamp") + final val opensavvy.ktmongo.dsl.path.Field.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfTimestamp") + final val kotlin.reflect.KProperty1.second: Value + get() = of(this).second + + /** + * Returns the second portion of a date as a number between `0` and `60` (leap seconds). + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthsecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthsecond set User::birthdate.second + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("secondOfTimestamp") + final val Timestamp.second: Value + get() = of(this).second + // endregion @LowLevelApi diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt index 16eece53..18024dba 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt @@ -27,6 +27,7 @@ val DateTimeValueOperatorsTest by multiContextSuite { val date: Instant, val year: Int, val week: Int, + val second: Int, ) test($$"$year") { @@ -65,4 +66,22 @@ val DateTimeValueOperatorsTest by multiContextSuite { """.trimIndent()) } + test($$"$second") { + TestPipeline() + .set { + Target::second set Target::date.second + } + .shouldBeBson($$""" + [ + { + "$set": { + "second": { + "$second": "$date" + } + } + } + ] + """.trimIndent()) + } + }