Skip to content

Commit 9b0f63a

Browse files
committed
Add description of the datetime.parse() method
Part of #2576
1 parent c4779cf commit 9b0f63a

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

doc/reference/reference_lua/datetime/datetime_object.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,69 @@ datetime_object
177177
---
178178
- 2021-08-20T18:25:20.567+0100
179179
...
180+
181+
.. _datetime-parse:
182+
183+
.. method:: parse( 'input_string'[, {format, tzoffset} ] )
184+
185+
Convert an input string with the date and time information into a ``datetime`` object.
186+
The input string should be formatted according to one of the following standards:
187+
188+
* ISO 8601
189+
* RFC 3339
190+
* extended `strftime <https://www.freebsd.org/cgi/man.cgi?query=strftime&sektion=3>`__ -- see description of the :ref:`format() <datetime-format>` for details.
191+
192+
:param string input_string: string with the date and time information.
193+
:param string format: indicator of the input_sting format. Possible values: 'iso8601', 'rfc3339', or ``strptime``-like format string.
194+
If no value is set, the default formating is used.
195+
:param number tzoffset: time zone offset from UTC, in minutes.
196+
197+
:return: a datetime_object
198+
:rtype: cdata
199+
200+
**Example:**
201+
202+
.. code-block:: tarantoolsession
203+
204+
tarantool> t = datetime.parse('1970-01-01T00:00:00Z')
205+
206+
tarantool> t
207+
---
208+
- 1970-01-01T00:00:00Z
209+
...
210+
211+
tarantool> t = datetime.parse('1970-01-01T00:00:00', {format = 'iso8601', tzoffset = 180})
212+
213+
tarantool> t
214+
---
215+
- 1970-01-01T00:00:00+0300
216+
...
217+
218+
tarantool> t = datetime.parse('2017-12-27T18:45:32.999999-05:00', {format = 'rfc3339'})
219+
220+
tarantool> t
221+
---
222+
- 2017-12-27T18:45:32.999999-0500
223+
...
224+
225+
tarantool> T = datetime.parse('Thu Jan 1 03:00:00 1970', {format = '%c'})
226+
227+
tarantool> T
228+
---
229+
- 1970-01-01T03:00:00Z
230+
...
231+
232+
tarantool> T = datetime.parse('12/31/2020', {format = '%m/%d/%y'})
233+
234+
tarantool> T
235+
---
236+
- 2020-12-31T00:00:00Z
237+
...
238+
239+
tarantool> T = datetime.parse('1970-01-01T03:00:00.125000000+0300', {format = '%FT%T.%f%z'})
240+
241+
tarantool> T
242+
---
243+
- 1970-01-01T03:00:00.125+0300
244+
...
245+

0 commit comments

Comments
 (0)