commit - 93fb2363cb45dc47a94eb221d5904b8b823e614d
commit + 9ac56a1222e916951010091fbdbfc497f4a4971d
blob - /dev/null
blob + b2264bd2c47e38c4efbaf2cd0f1663ae82af5734 (mode 644)
--- /dev/null
+++ changelogs/unreleased/gh-8588-setting-unspecified-fields-fix.md
+## bugfix/datetime
+
+* Fixed a bug with setting unspecified fields to undefined values
+ (gh-8588).
blob - d66cace43704a399c82a1ae0f12316467b90abbb
blob + 36d50fe0fbacfed9d1b72b02322a6ed6979c3780
--- src/lib/core/datetime.c
+++ src/lib/core/datetime.c
assert(date != NULL);
assert(fmt != NULL);
assert(buf != NULL);
- struct tnt_tm t = { .tm_epoch = 0 };
+ struct tnt_tm t;
+ /* Set to Unix time. */
+ struct datetime dt = {
+ .epoch = 0,
+ .nsec = 0,
+ .tzindex = 0,
+ .tzoffset = 0,
+ };
+ datetime_to_tm(&dt, &t);
char *ret = tnt_strptime(buf, fmt, &t);
if (ret == NULL)
return 0;
blob - 85a00b2afbd3ad00ccf514e303200b57a78509c0
blob + 4cf33d8e066bd119f09fdc310c01ca568bb78cc9
--- test/app-tap/datetime.test.lua
+++ test/app-tap/datetime.test.lua
local msgpack = require('msgpack')
local TZ = date.TZ
-test:plan(39)
+test:plan(41)
local INT_MAX = 2147483647
test:is(tostring(ts:set{month = 3, day = 2}), '1904-03-02T00:00:00Z',
'2 March')
test:is(tostring(ts:set{day = -1}), '1904-03-31T00:00:00Z', '31 March')
+end)
+
+test:test("Parse datetime with specified seconds", function(test)
+ test:plan(12)
+ local dt = date.parse('01', {format = '%S'})
+ test:is(dt.isdst, false, 'unspecified isdst')
+ test:is(dt.nsec, 0, 'unspecified nsec')
+ test:is(dt.sec, 1, 'specified seconds')
+ test:is(dt.min, 0, 'unspecified minutes')
+ test:is(dt.yday, 1, 'unspecified yday')
+ test:is(dt.day, 1, 'unspecified day')
+ test:is(dt.wday, 5, 'unspecified wday')
+ test:is(dt.tzoffset, 0, 'unspecified tzoffset')
+ test:is(dt.month, 1, 'unspecified month')
+ test:is(dt.year, 1970, 'unspecified year')
+ test:is(dt.hour, 0, 'unspecified hours')
+ test:is(dt.timestamp, 1, 'timestamp')
end)
+test:test("Parse datetime with unspecified seconds", function(test)
+ test:plan(2)
+ local dt = date.parse('01', {format = '%H'})
+ test:is(dt.sec, 0, 'uspecified sec')
+ test:is(dt.timestamp, 3600, 'timestamp')
+end)
+
os.exit(test:check() and 0 or 1)