commit - 255c808b4ba858f42db61dcd0277c8a4540a8324
commit + cbfa305fdd48612200b302da8e39c0f5d7bd64f2
blob - /dev/null
blob + d09b3ea7f5ea4919959a0683620cd92e433d8e10 (mode 644)
--- /dev/null
+++ changelogs/unreleased/gh-10331-tz-in-totable.md
+## bugfix/datetime
+
+* Added the `tz` field to a table produced by `:totable()`
+ (gh-10331).
blob - c26e1d3aa8c696f4e396c7f095c5c28f2faca84e
blob + 7daecb0761292325abda5a684bdfc40714869d92
--- src/lua/datetime.lua
+++ src/lua/datetime.lua
isdst = datetime_isdst(self),
nsec = self.nsec,
tzoffset = self.tzoffset,
+ tz = self.tz,
}
end
blob - 4cf33d8e066bd119f09fdc310c01ca568bb78cc9
blob + a7f1c7f5f729a18225f1370e7aad6e35b39e0d6e
--- test/app-tap/datetime.test.lua
+++ test/app-tap/datetime.test.lua
local msgpack = require('msgpack')
local TZ = date.TZ
-test:plan(41)
+test:plan(42)
local INT_MAX = 2147483647
local table_expected = {
sec = 0, min = 0, wday = 5, day = 1, nsec = 0,
isdst = false, yday = 1, tzoffset = 0, month = 1,
- year = 1970, hour = 0
+ year = 1970, hour = 0, tz = ''
}
test:is_deeply(local_totable(ts), table_expected, "correct :totable")
local date_expected = date.new()
test:plan(78)
local exp = {sec = 0, min = 0, wday = 5, day = 1,
nsec = 0, isdst = false, yday = 1,
- tzoffset = 0, month = 1, year = 1970, hour = 0}
+ tzoffset = 0, month = 1, year = 1970, hour = 0,
+ tz = ''}
local ts = date.new()
local totable = ts:totable()
test:is_deeply(totable, exp, 'date:totable()')
for _, key in pairs({'wday', 'day', 'yday', 'month', 'year'}) do
test:is(ts[key], osdate[key],
('[%s]: %s == %s'):format(key, ts[key], osdate[key]))
+ end
+end)
+
+test:test('totable() with timezone', function(test)
+ local DEFAULT_TZOFFSET = 0
+ local DEFAULT_TZ = ''
+
+ local MOSCOW_TZOFFSET = 180
+ local MOSCOW_TZ = 'Europe/Moscow'
+
+ local test_cases = {
+ -- Empty datetime value except the timezone.
+ {
+ dt = {tz = MOSCOW_TZ},
+ expected = {
+ tzoffset = MOSCOW_TZOFFSET,
+ tz = MOSCOW_TZ,
+ }
+ },
+ -- Empty datetime value except the tzoffset.
+ {
+ dt = {tzoffset = MOSCOW_TZOFFSET},
+ expected = {
+ tzoffset = MOSCOW_TZOFFSET,
+ tz = '',
+ }
+ },
+ -- Empty datetime value.
+ {
+ dt = {},
+ expected = {
+ tz = DEFAULT_TZ,
+ tzoffset = DEFAULT_TZOFFSET,
+ },
+ },
+ }
+
+ test:plan(#test_cases * 2)
+
+ for _, tc in pairs(test_cases) do
+ local dtab = date.new(tc.dt):totable()
+ local expected = tc.expected
+ test:is(dtab.tzoffset, expected.tzoffset,
+ ('[tzoffset]: %q == %q'):format(dtab.tzoffset,
+ expected.tzoffset))
+ test:is(dtab.tz, expected.tz,
+ ('[tz]: %q == %q'):format(dtab.tz, expected.tz))
end
end)
blob - 1ef0c95e7edb664a32491390fa361fb5579d3448
blob + d2efc2449b55c4bd17dba7bcab092d75b98029ad
--- test/sql-luatest/datetime_test.lua
+++ test/sql-luatest/datetime_test.lua
g.test_datetime_18_3 = function()
g.server:exec(function()
local dt = require('datetime')
- local dt1 = dt.new({year = 2001, month = 1, day = 1, hour = 1})
+ local dt1 = dt.new(
+ {year = 2001, month = 1, day = 1, hour = 1, tz = 'Z'})
local sql = [[SELECT CAST('2001-01-01T01:00:00Z' AS DATETIME);]]
local res = {{dt1}}
local rows = box.execute(sql).rows
g.test_datetime_32_1 = function()
g.server:exec(function()
local dt = require('datetime')
- local dt1 = dt.new({year = 2000, month = 2, day = 29, hour = 1})
+ local dt1 = dt.new(
+ {year = 2000, month = 2, day = 29, hour = 1, tz = 'Z'})
local sql = [[SELECT CAST('2000-02-29T01:00:00Z' AS DATETIME);]]
local res = {{dt1}}
local rows = box.execute(sql).rows