Skip to content

Commit

Permalink
feature: support datetime type
Browse files Browse the repository at this point in the history
Support datetime type checks [1] (added in Tarantool 2.10.0).

1. tarantool/tarantool#5941

Part of tarantool/tarantool#7726
  • Loading branch information
DifferentialOrange committed Jan 16, 2023
1 parent 031d6a1 commit db56511
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- "error" type supported.
- "datetime" type supported.

### Fixed

Expand Down
5 changes: 5 additions & 0 deletions checks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,9 @@ end

add_ffi_type_checker('error', 'struct error')

local has_datetime, datetime = pcall(require, 'datetime')
if has_datetime then
checkers.datetime = datetime.is_datetime
end

return checks
67 changes: 67 additions & 0 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,15 @@ end

local has_error = (box.error ~= nil) and (box.error.new ~= nil)

function testdata.fn_datetime(arg) -- luacheck: no unused args
checks('datetime')
end

local has_datetime, datetime = pcall(require, 'datetime')
if has_datetime then
testdata.datetime = datetime
end

local ret_cases = {
-- fn_int64
{
Expand Down Expand Up @@ -970,6 +979,64 @@ local ret_cases = {
code = 'fn_error(1)',
ok = false,
},

-- fn_datetime
{
skip = not has_datetime,
code = 'fn_datetime(datetime.new())',
ok = true,
additional_data = {'datetime'},
},
{
skip = not has_datetime,
code = 'fn_datetime(datetime.new{year=2023, month=1, day=11})',
ok = true,
additional_data = {'datetime'},
},
{
skip = not has_datetime,
code = 'fn_datetime(datetime.new{nsec=1001001})',
ok = true,
additional_data = {'datetime'},
},
{
skip = not has_datetime,
code = 'fn_datetime(datetime.new{timestamp=1673439642})',
ok = true,
additional_data = {'datetime'},
},
{
skip = not has_datetime,
code = 'fn_datetime(datetime.new{tzoffset=180})',
ok = true,
additional_data = {'datetime'},
},
{
skip = not has_datetime,
code = 'fn_datetime(datetime.new{tz="Europe/Moscow"})',
ok = true,
additional_data = {'datetime'},
},
{
skip = not has_datetime,
code = 'fn_datetime()',
ok = false,
},
{
skip = not has_datetime,
code = 'fn_datetime("1.11.2023")',
ok = false,
},
{
skip = not has_datetime,
code = 'fn_datetime(1673439642)',
ok = false,
},
{
skip = not has_datetime,
code = 'fn_datetime({year=2023, month=1, day=11})',
ok = false,
},
}

for _, case in pairs(ret_cases) do
Expand Down

0 comments on commit db56511

Please sign in to comment.