From 3050a460aa9e58b159c4600cbc2ef37efe90bb69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Mon, 24 Mar 2025 09:36:12 +0100 Subject: [PATCH 1/6] initial --- modules/ROOT/content-nav.adoc | 1 + modules/ROOT/pages/expressions/index.adoc | 1 + .../pages/expressions/temporal-operators.adoc | 128 ++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 modules/ROOT/pages/expressions/temporal-operators.adoc diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index 033767527..5bc92b6e8 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -75,6 +75,7 @@ *** xref:expressions/predicates/type-predicate-expressions.adoc[] ** xref:expressions/mathematical-operators.adoc[] ** xref:expressions/string-operators.adoc[] +** xref:expressions/temporal-operators.adoc[] ** xref:expressions/conditional-expressions.adoc[] * xref:functions/index.adoc[] diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index 97415b831..3dbcd364e 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -13,5 +13,6 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. * xref:expressions/string-operators.adoc[]: `+`, `||` +* xref:expressions/temporal-operators.adoc[]: `+`, `-`, `*`, `/` * xref:expressions/conditional-expressions.adoc[] diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc new file mode 100644 index 000000000..0eb27ebe5 --- /dev/null +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -0,0 +1,128 @@ += Temporal operators +:description: Information about Cypher's temporal operators. +:table-caption!: + +Cypher contains the following temporal operators: + +* Adding a xref::values-and-types/temporal.adoc#cypher-temporal-durations[`DURATION`] to either a xref::values-and-types/temporal.adoc#cypher-temporal-instants[temporal instant value] or another `DURATION`: `+` +* Subtracting a `DURATION` from either a temporal instant value or another `DURATION`: `-` +* Multiplying a `DURATION` with a number: `*` +* Dividing a `DURATION` by a number: `/` + +For additional expressions that evaluate to a xref:values-and-types/temporal.adoc[temporal value type], see: + +* xref:functions/temporal/index.adoc[Temporal functions -- instant types] +* xref:functions/temporal/duration.adoc[Temporal functions -- duration types] + + +.Value returned from temporal operators +[options="header"] +|=== +| Operator | Left-hand operand | Right-hand operand | Result value type + +| `+` +| Temporal instant +| `DURATION` +| The type of the temporal instant + +| `+` +| `DURATION` +| Temporal instant +| The type of the temporal instant + +| `-` +| Temporal instant +| `DURATION` +| The type of the temporal instant + +| `+` +| `DURATION` +| `DURATION` +| `DURATION` + +| `-` +| `DURATION` +| `DURATION` +| `DURATION` + +| `*` +| `DURATION` +| xref::values-and-types/property-structural-constructed.adoc#property-types[Number] +| `DURATION` + +| `*` +| xref::values-and-types/property-structural-constructed.adoc#property-types[Number] +| `DURATION` +| `DURATION` + +| `/` +| `DURATION` +| xref::values-and-types/property-structural-constructed.adoc#property-types[Number] +| `DURATION` + +|=== + +== Examples + + +.Adding and subtracting a `DURATION` to or from a temporal instant +[source, cypher] +---- +WITH localdatetime({year:1984, month:10, day:11, hour:12, minute:31, second:14}) AS aDateTime, + duration({years: 12, nanoseconds: 2}) AS aDuration +RETURN aDateTime + aDuration AS addition, aDateTime - aDuration AS subtraction +---- + +.Result +[role="queryresult",options="header,footer",cols="2* Date: Mon, 24 Mar 2025 13:00:59 +0100 Subject: [PATCH 2/6] second --- .../pages/expressions/temporal-operators.adoc | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc index 0eb27ebe5..c0ba497e7 100644 --- a/modules/ROOT/pages/expressions/temporal-operators.adoc +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -2,6 +2,7 @@ :description: Information about Cypher's temporal operators. :table-caption!: + Cypher contains the following temporal operators: * Adding a xref::values-and-types/temporal.adoc#cypher-temporal-durations[`DURATION`] to either a xref::values-and-types/temporal.adoc#cypher-temporal-instants[temporal instant value] or another `DURATION`: `+` @@ -14,7 +15,6 @@ For additional expressions that evaluate to a xref:values-and-types/temporal.ado * xref:functions/temporal/index.adoc[Temporal functions -- instant types] * xref:functions/temporal/duration.adoc[Temporal functions -- duration types] - .Value returned from temporal operators [options="header"] |=== @@ -62,14 +62,12 @@ For additional expressions that evaluate to a xref:values-and-types/temporal.ado |=== -== Examples - +== Adding and subtracting a `DURATION` to or from a temporal instant -.Adding and subtracting a `DURATION` to or from a temporal instant [source, cypher] ---- WITH localdatetime({year:1984, month:10, day:11, hour:12, minute:31, second:14}) AS aDateTime, - duration({years: 12, nanoseconds: 2}) AS aDuration + duration({years: 12, nanoseconds: 2}) AS aDuration RETURN aDateTime + aDuration AS addition, aDateTime - aDuration AS subtraction ---- @@ -83,18 +81,33 @@ RETURN aDateTime + aDuration AS addition, aDateTime - aDuration AS subtraction 2+d|Rows: 1 |=== +=== Ignored components of `DURATION` values + +When adding a `DURATION` to a temporal instant value, any xref::values-and-types/temporal.adoc#cypher-temporal-duration-component[components] that do not apply to that specific type are ignored. +For example, when adding a `DURATION` to a `DATE`, only the `years`, `months`, and `days` components of a `DURATION` value are considered, while `hours`, `minutes`, `seconds`, and `nanoseconds` are ignored. + +This behavior also applies to `LOCAL TIME` and `ZONED TIME`: since they only represent time (without a date), any years, months, or days in the DURATION are ignored. + + + + + + + xref::values-and-types/temporal.adoc#cypher-temporal-duration-component[Components of a `DURATION`] that do not apply to the temporal instant are ignored. For example, when adding a `DURATION` to a `DATE`, the _hours_, _minutes_, _seconds_ and _nanoseconds_ of the `DURATION` are ignored (`ZONED TIME` and `LOCAL TIME` behaves in an analogous manner): + .Query [source, cypher] ---- WITH - date({year:1984, month:10, day:11}) AS aDate, - duration({years: 12, nanoseconds: 2}) AS aDuration + date({year:1984, month:10, day:11}) AS aDate, + duration({years: 12, nanoseconds: 2}) AS aDuration RETURN aDate + aDuration, aDate - aDuration ---- + .Result [role="queryresult",options="header,footer",cols="2* Date: Mon, 24 Mar 2025 15:24:35 +0100 Subject: [PATCH 3/6] third --- .../pages/expressions/temporal-operators.adoc | 99 +++++++---- .../pages/functions/temporal/duration.adoc | 2 +- .../ROOT/pages/functions/temporal/index.adoc | 2 +- modules/ROOT/pages/syntax/operators.adoc | 166 ------------------ .../ROOT/pages/values-and-types/temporal.adoc | 4 +- 5 files changed, 69 insertions(+), 204 deletions(-) diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc index c0ba497e7..2c5fcf72d 100644 --- a/modules/ROOT/pages/expressions/temporal-operators.adoc +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -2,7 +2,6 @@ :description: Information about Cypher's temporal operators. :table-caption!: - Cypher contains the following temporal operators: * Adding a xref::values-and-types/temporal.adoc#cypher-temporal-durations[`DURATION`] to either a xref::values-and-types/temporal.adoc#cypher-temporal-instants[temporal instant value] or another `DURATION`: `+` @@ -62,13 +61,19 @@ For additional expressions that evaluate to a xref:values-and-types/temporal.ado |=== -== Adding and subtracting a `DURATION` to or from a temporal instant +[[adding-subtracting-durations]] +== Adding and subtracting `DURATION` values + +`DURATION` values can be added and subtracted from temporal instant values, such as `LOCAL DATETIME`. +In the below example, the xref:functions/temporal/index.adoc#functions-localdatetime[`localdatetime()`] function is used to create a `LOCAL DATETIME` value, and the xref:functions/temporal/duration.adoc#functions-durations[`duration()`] function is used to create a `DURATION` value. +.Add and subtract a `DURATION` value [source, cypher] ---- WITH localdatetime({year:1984, month:10, day:11, hour:12, minute:31, second:14}) AS aDateTime, - duration({years: 12, nanoseconds: 2}) AS aDuration -RETURN aDateTime + aDuration AS addition, aDateTime - aDuration AS subtraction + duration({years: 12, nanoseconds: 2}) AS aDuration +RETURN aDateTime + aDuration AS addition, + aDateTime - aDuration AS subtraction ---- .Result @@ -81,70 +86,96 @@ RETURN aDateTime + aDuration AS addition, aDateTime - aDuration AS subtraction 2+d|Rows: 1 |=== -=== Ignored components of `DURATION` values - -When adding a `DURATION` to a temporal instant value, any xref::values-and-types/temporal.adoc#cypher-temporal-duration-component[components] that do not apply to that specific type are ignored. -For example, when adding a `DURATION` to a `DATE`, only the `years`, `months`, and `days` components of a `DURATION` value are considered, while `hours`, `minutes`, `seconds`, and `nanoseconds` are ignored. - -This behavior also applies to `LOCAL TIME` and `ZONED TIME`: since they only represent time (without a date), any years, months, or days in the DURATION are ignored. - - - +When adding or subtracting a `DURATION` that results in a non-existing date, Cypher truncates the date to the nearest valid date. +For example, if adding 1 month to January 31st, the result will not be February 31st (an invalid date) but February 28th (or 29th in a leap year). +.Add 1 month to January 31st +[source, cypher] +---- +RETURN date("2011-01-31") + duration("P1M") AS truncatedDate +---- +.Result +[role="queryresult",options="header,footer",cols="1* Date: Mon, 24 Mar 2025 15:47:29 +0100 Subject: [PATCH 4/6] fourth --- .../deprecations-additions-removals-compatibility.adoc | 2 +- modules/ROOT/pages/expressions/temporal-operators.adoc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc index b7df09fdb..9210f2858 100644 --- a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc +++ b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc @@ -5732,7 +5732,7 @@ Replaced by xref:values-and-types/lists.adoc#cypher-list-comprehension[list comp | xref:functions/scalar.adoc#functions-randomuuid[randomUUID()] | Function | Added | | xref:values-and-types/temporal.adoc[Temporal types] | Functionality | Added | Supports storing, indexing and working with the following temporal types: Date, Time, LocalTime, DateTime, LocalDateTime and Duration. | xref:functions/temporal/index.adoc[Temporal functions] | Functionality | Added | Functions allowing for the creation and manipulation of values for each temporal type -- _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ and _Duration_. -| xref:syntax/operators.adoc#query-operators-temporal[Temporal operators] | Functionality | Added | Operators allowing for the manipulation of values for each temporal type -- _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ and _Duration_. +| xref:expressions/temporal-operators.adoc[Temporal operators] | Functionality | Added | Operators allowing for the manipulation of values for each temporal type -- _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ and _Duration_. | xref:functions/string.adoc#functions-tostring[toString()] | Function | Extended | Now also allows temporal values as input (i.e. values of type _Date_, _Time_, _LocalTime_, _DateTime_, _LocalDateTime_ or _Duration_). |=== diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc index 2c5fcf72d..c8188fa47 100644 --- a/modules/ROOT/pages/expressions/temporal-operators.adoc +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -6,7 +6,7 @@ Cypher contains the following temporal operators: * Adding a xref::values-and-types/temporal.adoc#cypher-temporal-durations[`DURATION`] to either a xref::values-and-types/temporal.adoc#cypher-temporal-instants[temporal instant value] or another `DURATION`: `+` * Subtracting a `DURATION` from either a temporal instant value or another `DURATION`: `-` -* Multiplying a `DURATION` with a number: `*` +* Multiplying a `DURATION` with a xref::values-and-types/property-structural-constructed.adoc#property-types[number (`INTEGER` or `FLOAT`)]: `*` * Dividing a `DURATION` by a number: `/` For additional expressions that evaluate to a xref:values-and-types/temporal.adoc[temporal value type], see: @@ -46,17 +46,17 @@ For additional expressions that evaluate to a xref:values-and-types/temporal.ado | `*` | `DURATION` -| xref::values-and-types/property-structural-constructed.adoc#property-types[Number] +| Number | `DURATION` | `*` -| xref::values-and-types/property-structural-constructed.adoc#property-types[Number] +| Number | `DURATION` | `DURATION` | `/` | `DURATION` -| xref::values-and-types/property-structural-constructed.adoc#property-types[Number] +| Number | `DURATION` |=== From ed83eb4e5a46174e35b99ee5485c931dafb0644e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Tue, 25 Mar 2025 15:01:27 +0100 Subject: [PATCH 5/6] small fix --- modules/ROOT/pages/expressions/temporal-operators.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc index c8188fa47..6018e87c7 100644 --- a/modules/ROOT/pages/expressions/temporal-operators.adoc +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -107,7 +107,7 @@ RETURN date("2011-01-31") + duration("P1M") AS truncatedDate When adding two `DURATION` values to a temporal instant value, the order in which the durations are applied affects the result. -.Query +.Add two `DURATION` values to a `DATE` [source, cypher] ---- RETURN (date("2011-01-31") + duration("P1M")) + duration("P12M") AS date1, From da5e1a3680e58c2f8ea151cd470031c752d6b7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Tue, 25 Mar 2025 15:07:15 +0100 Subject: [PATCH 6/6] standardise --- modules/ROOT/pages/expressions/temporal-operators.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/expressions/temporal-operators.adoc b/modules/ROOT/pages/expressions/temporal-operators.adoc index 6018e87c7..dd1b09e29 100644 --- a/modules/ROOT/pages/expressions/temporal-operators.adoc +++ b/modules/ROOT/pages/expressions/temporal-operators.adoc @@ -67,7 +67,7 @@ For additional expressions that evaluate to a xref:values-and-types/temporal.ado `DURATION` values can be added and subtracted from temporal instant values, such as `LOCAL DATETIME`. In the below example, the xref:functions/temporal/index.adoc#functions-localdatetime[`localdatetime()`] function is used to create a `LOCAL DATETIME` value, and the xref:functions/temporal/duration.adoc#functions-durations[`duration()`] function is used to create a `DURATION` value. -.Add and subtract a `DURATION` value +.Add and subtract a `DURATION` value to/from a `LOCAL DATETIME` [source, cypher] ---- WITH localdatetime({year:1984, month:10, day:11, hour:12, minute:31, second:14}) AS aDateTime, @@ -135,7 +135,7 @@ When adding or subtracting a `DURATION` value to a temporal instant value, any x For example, when adding a `DURATION` to a `DATE`, only the `year`, `month`, and `day` components of a `DURATION` value are considered, while `hour`, `minute`, `second`, and `nanosecond` are ignored. This behavior also applies to `LOCAL TIME` and `ZONED TIME`. -.Adding and subtracting a `DURATION` to/from a `DATE` +.Add and subtract a `DURATION` to/from a `DATE` [source, cypher] ---- WITH date({year:1984, month:10, day:11}) AS aDate, @@ -161,7 +161,7 @@ In multiplication, the value of each component is multiplied by the given factor If the result of the division does not fit into the original components, it overflows into smaller components (e.g. converting days into hours). This overflow also occurs when multiplying with fractions. -.Multiplying and dividing a `DURATION` value +.Multiply and divide a `DURATION` value [source, cypher] ---- WITH duration({days: 14, minutes: 12, seconds: 70, nanoseconds: 1}) AS aDuration