datetime_object | Tarantool
Tarantool
Check out the new release policy

datetime_object

object datetime_object

Since 2.10.0.

datetime_object:totable()

Convert the information from the datetime object into the table format. Resulting table has the following fields:

Field name Description
nsec Nanosecods
sec Seconds
min Minutes
hour Hours
day Day number
month Month number
year Year
wday Days since the beginning of the week
yday Days since the beginning of the year
isdst Is the DST (Daylight saving time) applicable for the date. Boolean.
tzoffset Time zone offset from UTC
Return:table with the date and time parameters
Rtype:table

Example:

tarantool> dt = datetime.new {
            sec = 20,
            min = 25,
            hour = 18,

            day = 20,
            month = 8,
            year = 2021,
            }
---
...

tarantool> dt:totable()
---
- sec: 20
  min: 25
  yday: 232
  day: 20
  nsec: 0
  isdst: false
  wday: 6
  tzoffset: 0
  month: 8
  year: 2021
  hour: 18
...
datetime_object:format(['convensions'])

Convert the standard datetime object presentation into a formatted string. The formatting convension specifications are the same as in the strftime library. Additional convension for nanoseconds is %f which also allows a modifier to control the output precision of fractional part: %5f (see the example below). If no arguments are set for the method, the default convensions are used: '%FT%T.%f%z' (see the example below).

Parameters:
  • convensions (string) – string consisting of zero or more conversion specifications and ordinary characters
Return:

string with the formatted date and time information

Rtype:

string

Example:

tarantool> dt = datetime.new {
            nsec = 123456789,

            sec = 20,
            min = 25,
            hour = 18,

            day = 20,
            month = 8,
            year = 2021,

            tzoffset  = 180
            }
---
...

tarantool> dt:format('%d.%m.%y %H:%M:%S.%5f')
---
- 20.08.21 18:25:20.12345
...

tarantool> dt:format()
---
- 2021-08-20T18:25:20.123456789+0300
...

tarantool> dt:format('%FT%T.%f%z')
---
- 2021-08-20T18:25:20.123456789+0300
...
datetime_object:set([{ units }])

Update the field values in the existing datetime object.

Parameters:
  • units (table) – Table of time units. The time units are the same as for the datetime.new() function.
Return:

updated datetime_object

Rtype:

cdata

Example:

tarantool> dt = datetime.new {
            nsec = 123456789,

            sec = 20,
            min = 25,
            hour = 18,

            day = 20,
            month = 8,
            year = 2021,

            tzoffset  = 180
            }

tarantool> dt:set {msec = 567}
---
- 2021-08-20T18:25:20.567+0300
...

tarantool> dt:set {tzoffset = 60}
---
- 2021-08-20T18:25:20.567+0100
...
datetime_object:parse('input_string'[, {format, tzoffset}])

Convert an input string with the date and time information into a datetime object. The input string should be formatted according to one of the following standards:

  • ISO 8601
  • RFC 3339
  • extended strftime – see description of the format() for details.
Parameters:
  • input_string (string) – string with the date and time information.
  • format (string) – indicator of the input_sting format. Possible values: ‘iso8601’, ‘rfc3339’, or strptime-like format string. If no value is set, the default formating is used.
  • tzoffset (number) – time zone offset from UTC, in minutes.
Return:

a datetime_object

Rtype:

cdata

Example:

tarantool> t = datetime.parse('1970-01-01T00:00:00Z')

tarantool> t
---
- 1970-01-01T00:00:00Z
...

tarantool> t = datetime.parse('1970-01-01T00:00:00', {format = 'iso8601', tzoffset = 180})

tarantool> t
---
- 1970-01-01T00:00:00+0300
...

tarantool> t = datetime.parse('2017-12-27T18:45:32.999999-05:00', {format = 'rfc3339'})

tarantool> t
---
- 2017-12-27T18:45:32.999999-0500
...

tarantool> T = datetime.parse('Thu Jan  1 03:00:00 1970', {format = '%c'})

tarantool> T
---
- 1970-01-01T03:00:00Z
...

tarantool> T = datetime.parse('12/31/2020', {format = '%m/%d/%y'})

tarantool> T
---
- 2020-12-31T00:00:00Z
...

tarantool> T = datetime.parse('1970-01-01T03:00:00.125000000+0300', {format = '%FT%T.%f%z'})

tarantool> T
---
- 1970-01-01T03:00:00.125+0300
...
Found what you were looking for?
Feedback