Skip to content

Commit 43b1af5

Browse files
committed
datetime: describe relational operators
Follows up commit de58780 ("Add a new section for the datetime module with the description of its main functions and methods"). Datetime comparison has been added in [1] (since 2.10.0-beta2), interval comparison has been added in commit [2] (since 2.11.0-rc1). 1. tarantool/tarantool@43e10ed 2. tarantool/tarantool@65a3c17 Folows up #2411
1 parent 0ff90ef commit 43b1af5

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

doc/reference/reference_lua/datetime.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,3 +964,53 @@ The matrix of the ``subtraction`` operands eligibility and their result types:
964964
- unsupported
965965
- interval
966966
- interval
967+
968+
.. _interval_comp:
969+
970+
Datetime and interval comparison
971+
--------------------------------
972+
973+
If you need to compare the ``datetime`` and ``interval`` object values, you can use standard Lua relational operators: ``==`` , ``~=``, ``>``, ``<``, ``>=`` and ``<=`` using overloaded metamethods (``__eq``, ``__lt``, ``__le``).
974+
975+
Support of relational operators for ``interval`` objects has been added since: :doc:`2.11.0 </release/2.11.0>`.
976+
977+
**Example 1:**
978+
979+
.. code-block:: tarantoolsession
980+
981+
tarantool> dt1 = datetime.now()
982+
---
983+
...
984+
985+
tarantool> dt2 = datetime.now()
986+
---
987+
...
988+
989+
tarantool> dt1 == dt2
990+
---
991+
- false
992+
...
993+
994+
tarantool> dt1 < dt2
995+
---
996+
- true
997+
...
998+
999+
**Example 2:**
1000+
1001+
.. code-block:: tarantoolsession
1002+
1003+
tarantool> iv1 = datetime.interval.new({month = 1})
1004+
---
1005+
...
1006+
1007+
tarantool> iv2 = datetime.interval.new({month = 2})
1008+
---
1009+
...
1010+
1011+
tarantool> iv1 < iv2
1012+
---
1013+
- true
1014+
...
1015+
1016+
tarantool>

0 commit comments

Comments
 (0)