diff --git a/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/AggregationOperators.kt index a77bae82..58aa1c42 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: + * - [`$millisecond`][DateTimeValueOperators.millisecond] * - [`$minute`][DateTimeValueOperators.minute] * - [`$month`][DateTimeValueOperators.month] * - [`$second`][DateTimeValueOperators.second] diff --git a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt index ee4a1acd..6e27eab3 100644 --- a/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl-template/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -514,6 +514,100 @@ interface DateTimeValueOperators : ValueOperators { final val Value.minute: Value get() = UnaryOperator(context, "minute", this) + // endregion + // region $millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + val Value.millisecond: Value + get() = UnaryOperator(context, "millisecond", this) + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfObjectId") + final val Value.millisecond: Value + get() = UnaryOperator(context, "millisecond", this) + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfTimestamp") + final val Value.millisecond: Value + get() = UnaryOperator(context, "millisecond", this) + // endregion @LowLevelApi diff --git a/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt b/dsl/src/commonMain/kotlin/aggregation/AggregationOperators.kt index 100350af..26c71e7e 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: + * - [`$millisecond`][DateTimeValueOperators.millisecond] * - [`$minute`][DateTimeValueOperators.minute] * - [`$month`][DateTimeValueOperators.month] * - [`$second`][DateTimeValueOperators.second] diff --git a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt index 2260b0d6..f7218305 100644 --- a/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt +++ b/dsl/src/commonMain/kotlin/aggregation/operators/DateTimeValueOperators.kt @@ -1929,6 +1929,377 @@ interface DateTimeValueOperators : ValueOperators { final val Timestamp.minute: Value get() = of(this).minute + // endregion + // region $millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + val Value.millisecond: Value + get() = UnaryOperator(context, "millisecond", this) + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + val opensavvy.ktmongo.dsl.path.Field.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + val kotlin.reflect.KProperty1.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @Suppress("INVISIBLE_REFERENCE") + @OptIn(LowLevelApi::class) + val Instant.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfObjectId") + final val Value.millisecond: Value + get() = UnaryOperator(context, "millisecond", this) + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfObjectId") + final val opensavvy.ktmongo.dsl.path.Field.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfObjectId") + final val kotlin.reflect.KProperty1.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfObjectId") + final val ObjectId.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfTimestamp") + final val Value.millisecond: Value + get() = UnaryOperator(context, "millisecond", this) + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfTimestamp") + final val opensavvy.ktmongo.dsl.path.Field.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @OptIn(LowLevelApi::class) + @Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfTimestamp") + final val kotlin.reflect.KProperty1.millisecond: Value + get() = of(this).millisecond + + /** + * Returns the millisecond portion of a date as a number between `0` and `999`. + * + * The accepted date types are [Instant], [ObjectId] and [Timestamp]. + * + * ### Example + * + * ```kotlin + * class User( + * val name: String, + * val birthdate: Instant, + * val birthmillisecond: Int? = null, + * ) + * + * users.updateManyWithPipeline { + * set { + * User::birthmillisecond set User::birthdate.millisecond + * } + * } + * ``` + * + * ### External resources + * + * - [Official documentation](https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/) + */ + @kotlin.internal.LowPriorityInOverloadResolution + @OptIn(LowLevelApi::class) + @Suppress("INVISIBLE_REFERENCE", "WRONG_MODIFIER_CONTAINING_DECLARATION") + @get:JvmName("millisecondOfTimestamp") + final val Timestamp.millisecond: Value + get() = of(this).millisecond + // endregion @LowLevelApi diff --git a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt index 182fe416..eea65d8f 100644 --- a/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt +++ b/dsl/src/commonTest/kotlin/aggregation/operators/DateTimeValueOperatorsTest.kt @@ -30,6 +30,7 @@ val DateTimeValueOperatorsTest by multiContextSuite { val second: Int, val month: Int, val minute: Int, + val millisecond: Int, ) test($$"$year") { @@ -122,4 +123,22 @@ val DateTimeValueOperatorsTest by multiContextSuite { """.trimIndent()) } + test($$"$millisecond") { + TestPipeline() + .set { + Target::millisecond set Target::date.millisecond + } + .shouldBeBson($$""" + [ + { + "$set": { + "millisecond": { + "$millisecond": "$date" + } + } + } + ] + """.trimIndent()) + } + }