From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id AB2446EC40; Tue, 17 Aug 2021 18:50:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AB2446EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629215423; bh=M7/HLUL3hRj+TPh+so1deiTQqkkjvV0h92dmZgY9hIA=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wZOV/SrIdbXs3gBBS2nBroY7Pw17BsksUBDrea5D+C+BoyonjiRPmcjQXLY1S7lbV 9uDg5ykrNlpEN3WZCZCQGB2IOh2ZpmoSJLnhDY8dH8FdBYsiCXpAx4HGeTCsi4siIs LG43exbuDnLKMMiqDsblO7UeawRSOPWc1E0V8X0w= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 688B26EC40 for ; Tue, 17 Aug 2021 18:50:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 688B26EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mG1M5-0006Vs-57; Tue, 17 Aug 2021 18:50:21 +0300 Date: Tue, 17 Aug 2021 18:50:19 +0300 To: Timur Safin via Tarantool-patches Message-ID: <20210817155019.zsvbxiz7dvc4cpo4@esperanza> References: <25f9e4a85319d7b4d1fa4fe70d9e9fb30b43c78d.1629071531.git.tsafin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <25f9e4a85319d7b4d1fa4fe70d9e9fb30b43c78d.1629071531.git.tsafin@tarantool.org> X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD910164DC12A5633065676A9727AC27C74182A05F53808504028A7623B6DBE42ADF1140D1BE8AC68185382E62B975D9171F9BD5ADF88C3F1D7 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7B9FBA884A7C9B8BAEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373318DFCEF5C6D9308638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D887D17075429BDF9A84EA89FF7A35BA3E117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C565C1E6824D8037B43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505EAAD191DA062472E6DB3D91653E30048 X-C1DE0DAB: 0D63561A33F958A534DA2482884A3C8CF29FD8ECE7B16098913FD1D536478C0AD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA757E10A58996CBD514410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A541DB4061E93832A94A1AA92996FFB9E5AF169DDD53D4CB8A799F51AD02A4106DC55ED63937A61D1D7E09C32AA3244CDAC3555872039BAEC1A8FBAD5A46D1C1F94338140B71B8EE83B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojuRQ/H5n28tqLF49TlGNlEQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D09E0279323CDF57EB7F5EE3656DDA5B5274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 1/8] build: add Christian Hansen c-dt to the build X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Cc: v.shpilevoy@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Mon, Aug 16, 2021 at 02:59:35AM +0300, Timur Safin via Tarantool-patches wrote: > * Integrated chansen/c-dt parser as 3rd party module to the > Tarantool cmake build process; > * Points to tarantool/c-dt instead of original chansen/c-dt to > have easier build integration, because there are additional > commits which have integrated cmake support and have established > symbols renaming facilities (similar to those we see in xxhash > or icu). > We have to be able to rename externally public symbols to avoid > name clashes with 3rd party modules. We prefix c-dt symbols > in the Tarantool build with `tnt_` prefix; I don't see this done in this patch. Looks like this is done by patch 2. > * took special care that generated build artifacts not override > in-source files, but use different build/ directory. > > * added datetime parsing unit tests, for literals - with and > without trailing timezones; > * also we check that strftime is reversible and produce consistent > results after roundtrip from/to strings; > * discovered the harder way that on *BSD/MacOSX `strftime()` format > `%z` outputs local time-zone if passed `tm_gmtoff` is 0. > This behaviour is different to that we observed on Linux, thus we > might have different execution results. Made test to not use `%z` > and only operate with normalized date time formats `%F` and `%T` > > Part of #5941 > --- > .gitmodules | 3 + > CMakeLists.txt | 8 + > cmake/BuildCDT.cmake | 8 + > src/CMakeLists.txt | 3 +- > test/unit/CMakeLists.txt | 3 +- > test/unit/datetime.c | 223 ++++++++++++++++++++++++ > test/unit/datetime.result | 358 ++++++++++++++++++++++++++++++++++++++ > third_party/c-dt | 1 + > 8 files changed, 605 insertions(+), 2 deletions(-) > create mode 100644 cmake/BuildCDT.cmake > create mode 100644 test/unit/datetime.c > create mode 100644 test/unit/datetime.result > create mode 160000 third_party/c-dt > > diff --git a/test/unit/datetime.c b/test/unit/datetime.c > new file mode 100644 > index 000000000..64c19dac4 > --- /dev/null > +++ b/test/unit/datetime.c > @@ -0,0 +1,223 @@ > +#include "dt.h" > +#include > +#include > +#include > +#include > + > +#include "unit.h" > + > +static const char sample[] = "2012-12-24T15:30Z"; > + > +#define S(s) {s, sizeof(s) - 1} > +struct { > + const char * sz; Extra space after '*'. We usually name a variable that stores a zero-terminated 's' or 'str', never 'sz'. > +#define DIM(a) (sizeof(a) / sizeof(a[0])) There's 'lengthof' helper already defined for this. > + > +/* p5-time-moment/src/moment_parse.c: parse_string_lenient() */ I don't understand the purpose of this comment. > +static int > +parse_datetime(const char *str, size_t len, int64_t *sp, int32_t *np, > + int32_t *op) What's 'sp', 'np', and 'op'? Please refrain from using confusing abbreviations. > +{ > + size_t n; > + dt_t dt; > + char c; > + int sod = 0, nanosecond = 0, offset = 0; > + > + n = dt_parse_iso_date(str, len, &dt); > + if (!n) > + return 1; > + if (n == len) > + goto exit; > + > + c = str[n++]; > + if (!(c == 'T' || c == 't' || c == ' ')) > + return 1; > + > + str += n; > + len -= n; > + > + n = dt_parse_iso_time(str, len, &sod, &nanosecond); > + if (!n) > + return 1; > + if (n == len) > + goto exit; > + > + if (str[n] == ' ') > + n++; Bad indentation. > + > + str += n; > + len -= n; > + > + n = dt_parse_iso_zone_lenient(str, len, &offset); > + if (!n || n != len) > + return 1; > + > +exit: > + *sp = ((int64_t)dt_rdn(dt) - 719163) * 86400 + sod - offset * 60; Please define and use appropriate constants to make the code easier for understanding: DAYS_PER_YEAR, MINUTES_PER_HOUR, etc. > + *np = nanosecond; > + *op = offset; > + > + return 0; > +} > + > +/* avoid introducing external datetime.h dependency - > + just copy paste it for today > +*/ Bad comment formatting. > +#define SECS_PER_DAY 86400 > +#define DT_EPOCH_1970_OFFSET 719163 > + > +struct datetime { > + double secs; > + int32_t nsec; > + int32_t offset; > +}; I see that this struct as well as some functions in this module are defined in src/lib/core/datetime in patch 2, and then you remove struct datetime from this test in patch 3, but leave the helper functions datetime_to_tm, parse_datetime. This makes me think that: - You should squash patches 1-3. - Both datetime and datetime manipulating functions (including parse_datetime) should be defined only in src/lib/core/datetime while test/unit should depend on src/lib/core/datetime. > + > +static int > +local_rd(const struct datetime *dt) > +{ > + return (int)((int64_t)dt->secs / SECS_PER_DAY) + DT_EPOCH_1970_OFFSET; > +} > + > +static int > +local_dt(const struct datetime *dt) > +{ > + return dt_from_rdn(local_rd(dt)); > +} > + > +struct tm * > +datetime_to_tm(struct datetime *dt) > +{ > + static struct tm tm; > + > + memset(&tm, 0, sizeof(tm)); > + dt_to_struct_tm(local_dt(dt), &tm); > + > + int seconds_of_day = (int64_t)dt->secs % 86400; > + tm.tm_hour = (seconds_of_day / 3600) % 24; > + tm.tm_min = (seconds_of_day / 60) % 60; > + tm.tm_sec = seconds_of_day % 60; > + > + return &tm; > +} > + > +static void datetime_test(void) > +{ > + size_t index; > + int64_t secs_expected; > + int32_t nanosecs; > + int32_t ofs; offset? > + > + plan(355); > + parse_datetime(sample, sizeof(sample) - 1, > + &secs_expected, &nanosecs, &ofs); > + > + for (index = 0; index < DIM(tests); index++) { > + int64_t secs; > + int rc = parse_datetime(tests[index].sz, tests[index].len, > + &secs, &nanosecs, &ofs); > + is(rc, 0, "correct parse_datetime return value for '%s'", > + tests[index].sz); > + is(secs, secs_expected, "correct parse_datetime output " > + "seconds for '%s", tests[index].sz); > + > + /* check that stringized literal produces the same date */ > + /* time fields */ > + static char buff[40]; > + struct datetime dt = {secs, nanosecs, ofs}; > + /* datetime_to_tm returns time in GMT zone */ > + struct tm * p_tm = datetime_to_tm(&dt); Extra space after '*'. > + size_t len = strftime(buff, sizeof buff, "%F %T", p_tm); > + ok(len > 0, "strftime"); > + int64_t parsed_secs; > + int32_t parsed_nsecs, parsed_ofs; > + rc = parse_datetime(buff, len, &parsed_secs, &parsed_nsecs, &parsed_ofs); > + is(rc, 0, "correct parse_datetime return value for '%s'", buff); > + is(secs, parsed_secs, > + "reversible seconds via strftime for '%s", buff); > + } > +} > + > +int > +main(void) > +{ > + plan(1); > + datetime_test(); > + > + return check_plan(); > +}