Skip to content

Commit 70c8f78

Browse files
authored
Add missed datetime information (#4420)
1 parent a222bf5 commit 70c8f78

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

doc/reference/reference_lua/datetime.rst

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Functions
118118
- 0
119119

120120
* - sec
121-
- Seconds. Value range: 0 - 60.
121+
- Seconds. Value range: 0 - 60. A leap second is supported, see a section :ref:`leap second <leap-second>`.
122122
- number
123123
- 0
124124

@@ -263,9 +263,14 @@ Functions
263263
* RFC 3339
264264
* extended `strftime <https://www.freebsd.org/cgi/man.cgi?query=strftime&sektion=3>`__ -- see description of the :ref:`format() <datetime-format>` for details.
265265

266+
By default fields that are not specified are equal to appropriate values in a Unix time.
267+
268+
Leap second is supported, see a section :ref:`leap second <leap-second>`.
269+
266270
:param string input_string: string with the date and time information.
267-
:param string format: indicator of the input_sting format. Possible values: 'iso8601', 'rfc3339', or ``strptime``-like format string.
268-
If no value is set, the default formatting is used.
271+
:param string format: indicator of the ``input_string`` format.
272+
Possible values: 'iso8601', 'rfc3339', or ``strptime``-like format string.
273+
If no value is set, the default formatting is used (``"%F %T %Z"``).
269274
:param number tzoffset: time zone offset from UTC, in minutes.
270275

271276
:return: a datetime_object
@@ -318,6 +323,25 @@ Functions
318323
- 1970-01-01T03:00:00.125+0300
319324
...
320325
326+
tarantool> dt = datetime.parse('01:01:01', {format ='%H:%M:%S'})
327+
---
328+
...
329+
330+
tarantool> dt.year
331+
---
332+
- 1970
333+
...
334+
335+
tarantool> dt.month
336+
---
337+
- 1
338+
...
339+
340+
tarantool> dt.wday
341+
---
342+
- 5
343+
...
344+
321345
.. _datetime-interval-is_interval:
322346

323347
.. function:: datetime.interval.is_interval([value])
@@ -584,7 +608,7 @@ datetime_object
584608
.. method:: format( ['input_string'] )
585609

586610
Convert the standard ``datetime`` object presentation into a formatted string.
587-
The conversion specifications are the same as in the `strftime <https://www.freebsd.org/cgi/man.cgi?query=strftime&sektion=3>`__ library.
611+
The conversion specifications are the same as in the `strftime <https://www.freebsd.org/cgi/man.cgi?query=strftime&sektion=3>`__ function.
588612
Additional specification for nanoseconds is `%f` which also allows a modifier to control the output precision of fractional part: `%5f` (see the example below).
589613
If no arguments are set for the method, the default conversions are used: `'%FT%T.%f%z'` (see the example below).
590614

@@ -1012,3 +1036,56 @@ Support for relational operators for ``interval`` objects has been added since :
10121036
---
10131037
- true
10141038
...
1039+
1040+
.. _leap-second:
1041+
1042+
Leap second
1043+
-----------
1044+
1045+
`Leap seconds <https://en.wikipedia.org/wiki/Leap_second>`__ are a periodic
1046+
one-second adjustment of Coordinated Universal Time(UTC) in order to keep
1047+
a system's time of day close to the mean solar time. However,
1048+
the Earth's rotation speed varies in response to climatic and geological events,
1049+
and due to this, UTC leap seconds are irregularly spaced and unpredictable.
1050+
1051+
Tarantool includes the `Time Zone Database <https://www.iana.org/time-zones>`__
1052+
that beside the time zone description files also contains a leapseconds file.
1053+
1054+
This section describes how the ``datetime`` module supports leap seconds:
1055+
1056+
* The function :ref:`datetime.parse() <datetime-parse>` correctly parses
1057+
an input string with 60 seconds:
1058+
1059+
.. code-block:: tarantoolsession
1060+
1061+
tarantool> datetime.parse('23:12:60', {format ='%H:%M:%S'})
1062+
---
1063+
- 1970-01-01T23:13:00Z
1064+
- 8
1065+
...
1066+
1067+
* The :ref:`datetime.new() <datetime-new>` function and the
1068+
:ref:`datetime_object:set() <datetime-set>` method accept a table with the ``sec`` key set to 60 seconds:
1069+
1070+
.. code-block:: tarantoolsession
1071+
1072+
tarantool> datetime.new({ sec = 60 })
1073+
---
1074+
- 1970-01-01T00:01:00Z
1075+
...
1076+
1077+
Limitations
1078+
-----------
1079+
1080+
The supported date range is from ``-5879610-06-22`` to ``+5879611-07-11``.
1081+
1082+
References
1083+
----------
1084+
1085+
* `RFC 3339: Date and Time on the Internet: Timestamps <https://www.rfc-editor.org/rfc/rfc3339>`_
1086+
1087+
* `ISO 8601: Date and time format <https://www.iso.org/iso-8601-date-and-time-format.html>`_
1088+
1089+
* `Lua 5.1 Reference Manual: 5.8 – Operating System Facilities <https://www.lua.org/manual/5.1/manual.html#pdf-os.date>`_
1090+
1091+
* `Lua Programming in Lua: 22.1 – Date and Time <https://www.lua.org/pil/22.1.html>`_

0 commit comments

Comments
 (0)