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 61FE36EC55; Thu, 15 Jul 2021 19:57:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 61FE36EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626368220; bh=mJZvZiZzqP0qx8xUuobL+tI02t41bHeKFOcuC8bSy7U=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=la/56h7c/zX3oJ4ELbe1qDZor618W/Rrg/wMgdTTxr7U//o+9cOk/VY82vUj2PqfB DxWmU2AoaO/fErwiQ8Cls3iQufT/8PxhPPImkZPRdRuaKK8CYqFJ+e8Y8TKhDe4gCM G3BQIDXxxHmOcwP8aNNJWbw4wUAYAeRp16h6tTAs= Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [94.100.177.106]) (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 D4B066EC55 for ; Thu, 15 Jul 2021 19:56:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D4B066EC55 Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1m44fS-0006HS-5E for tarantool-patches@dev.tarantool.org; Thu, 15 Jul 2021 19:56:58 +0300 To: tarantool-patches@dev.tarantool.org References: Message-ID: <5deb9cc2-3a74-9968-0fcc-aa0a1f851fb9@tarantool.org> Date: Thu, 15 Jul 2021 19:56:57 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C386C8E0DDEE7E2465E4A01A82547D9FE1182A05F5380850401ACA4E9745F4201603EA4811EC062EE29A223D5495098EDFE062244267E21BA9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70A10A23A3B64B805EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EF59B520676799BC8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E2D0445EA7EFDEF770C0167540AF257F117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FC58E42838E3597E443AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F79006377CF2F09735AFCD0ED81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F83C798A30B85E16BC6EABA9B74D0DA47B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A569F633E175ABF6B3624183DED832724CBCDDEB1618B52DB0D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34DFB7A809FB5370871EF1E23831BE217B4AA5DB9A2B0E523E419233BC5045567EC9776EA5DB51CE4F1D7E09C32AA3244C6512A9CC756D39EC12D34D085BD008ADF522A1CF68F4BE053EB3F6AD6EA9203E X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojSyb42jm8PHKWuJ3CLs2uWw== X-Mailru-Sender: 583F1D7ACE8F49BD1042885CEC987B6B3959BC3476BB1D0103EA4811EC062EE252685D71546B8E9E7019711D9D5B048E1458020726E2BC9FD5ECBA0B92C0A936CDC7563AA7CEBD287402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support 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: Oleg Babin via Tarantool-patches Reply-To: Oleg Babin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for your patch. I'd want to use native datetime data type in one project that should be released soon. So I'll give you some feedback because I'm really interested in this patch. I probably won't perform deep review and I'll just give some feedback about an interface. 1. I see you implemented "datetime" module as ffi wrapper over c-dt. Why did you choose FFI and could you show that FFI is better than Lua C API? I know there are such benchmark for decimal and they show that FFI was slower than Lua C API (https://github.com/tarantool/tarantool/issues/692#issuecomment-505043929). 2. Could you please implement a hepler `is_datetime`? Uuid and decimal have is_* methods. 3. Modue throws unhandled error: ``` tarantool> datetime.now() == newproxy() --- - error: 'builtin/datetime.lua:232: attempt to index local ''rhs'' (a userdata value)' ... ``` I think you can see how works uuid module (https://github.com/tarantool/tarantool/blob/master/src/lua/uuid.lua) to fix such errors. 4. Parse function has quite strange output format ``` tarantool> datetime.parse_date('2016-12-18') --- - 2016-12-18T00:00Z - 10 ... tarantool> datetime.parse_date('2016-13-18') --- - null - 0 ... ``` Do we really need the second value in case of success? Do we really need 0 as the second return value in case of failue? Probably we should extend error message somehow. 5. More strange errors, please improve the validation. ``` tarantool> datetime.days() --- - error: 'builtin/datetime.lua:203: attempt to perform arithmetic on local ''d'' (a     nil value)' ... tarantool> datetime.ctime() --- - error: 'builtin/datetime.lua:550: bad argument #1 to ''typeof'' (C type expected,     got nil)' ... ``` Also I see some assertions in code (e.g. `assert(v >= 0 and v < 61)`). This yields to "assertion failed" message that is not completely clear. 6. Does this module allows to manipulate with timezones and locales? Icu-date that we currently use allows it (https://github.com/tarantool/icu-date). Also try to use tests from icu-date module. I think it could be useful. The best option is to allow drop-in but I'm not sure that it's possible. 7. Is it expected? ``` tarantool> datetime.now() - datetime.now() --- - +18823 days, 16 hours, 29 minutes, 44.178836107254 seconds ... ``` I believe it should be 0. 8. Could you provide a helper that allows to convert unix time to datetime? I tried this way but it seems an interval instead of datetime. ``` tarantool> datetime.seconds(datetime.now().seconds) --- - +18823 days, 16 hours, 34 minutes, 10.283248901367 seconds ... ``` 9. Lua output doesn't support datetime ``` tarantool> \set output yaml --- - true ... tarantool> datetime.now() --- - 2021-07-15T19:46:15.797333+03:00 ... tarantool> \set output lua true; tarantool> datetime.now() nil; ``` 10. You can export also the number of months/days in week as constansts. Probably it could be useful to make something like: ``` datetime_object:set('month', datetime.months.JANUARY) ``` It was brief feedback as from (I hope) future customer of this module. If I've found another interface issues I'll give you feedback in next e-mails. I didn't see code itself if you need it I can review this patchset in more detailed way.  On 15.07.2021 11:18, Timur Safin via Tarantool-patches wrote: > Here is the preliminary RFC version of a patchset, which is implementing > datetime lua support in box, their messagepack, yaml, json serialization > support, and a set of c and lua tests. > > * It's heavily influenced by Sci-Lua lua-time module implementation > https://github.com/stepelu/lua-time > e.g. you could find very similar approach for handling of operations > with year and months periods (which should be handled differently than > usual seconds, days periods). > > * But internally it actually uses Christina Hanson' c-dt module > https://github.com/chansen/c-dt > (though it has been modified slightly for cleaner integration > into cmake build process) > > This is preliminary version of patchset, with unoptimal patches divisions > (like you could see patches with rename refactorings), but, due to an amount > of code in patchset, and limited time have, I send patchset as RFC today, > expecting to receive initial feedback for various parts of a series. > > Prior plan was to split series into one, which introduces datetime module api, > and another one with datetime messagepack serialization implementation. > But here they left as part of a same series. Sorry, for invonvenience - I'll > reshuffle order according to feedback provided. > > The problem, which was stopping such simple division - that `datetime.lua` > module uses `datetime_to_string()` ffi function for stringization of a > datetime object. And this function has been introduced as part of > messagepack/yaml/json serialization support. Yes, intra-dependendencies > between parts looks suboptimal, and I'm very open to suggestions how to > divide it properly. > > Module API > ========== > > To simplify review of a code in patchset below you could find preliminary > documentation of a datetime api module. Eventually we may put it > as .rst file in documentation repository (though, personally, I'd prefer > to have all modules api committed to the same repo as code, but I digress) > > Datetime module > =============== > > This module allows to parse date/time stamps, manipulate with them, and > generate textual representation. Parsing of date constants will handle > all ISO-8601 formats, and deal with some extensions. > > For internal date representation it uses cdata structures of a form: > > ```c++ > struct t_datetime { > int secs; > int nsecs; > int offset; > }; > ``` > > Where: > > - secs is the (signed) number of seconds since epoch 1970-01-01T00:00Z; > - nsecs is number of nanoseconds since beginning of day; > - offset is the timezone offset (in minutes); > > `datetime()` � create datetime object > ------------------------------------- > > Create date/time object using either string literals, or initialization > object. When given string literals it behaves like wrapper around > parse() method. > > When there is initialization object it could create date/time object > using these attributes below: > > | **Easy way** | | > |--------------|-------------------------------------------------------------------------------------------------| > | secs | Seconds since epoch | > | nsec | Nanoseconds since midnight | > | offset | Time-zone offset in minutes | > | **YMD part** | | > | year | Year in range \[1..9999\] | > | month | Month in range \[1..12\] | > | day | Day in month in range \[1..31\] | > | **HMS part** | | > | hour | Hour in range \[0..23\] | > | minute | Minute in range \[0..59\] | > | second | Seconds in range \[0..60\]. It allows to have fraction part in which case it goes to nsec field | > | tz | Timezone offset (in minutes) for HMS part | > > Example: > > ```lua > > datetime = require `datetime` > > d = datetime{secs = 0, nsec = 0, offset = 0} > d = datetime(�1970-01-01�) > d = datetime{year = 1970, month = 1, day = 1} > ``` > > `delta()` � create time duration object > --------------------------------------- > > TBD > > `parse()` � parse full ISO-8601 string > -------------------------------------- > > Parse full length date/time literal, which may be in ISO-8601 format of > any of extended formats supported by `parse_date()`, `parse_time()` or > `parse_timezone()` > > It deals with date/time string in format > > `date ([Tt ] time ([ ] time_zone)? )?` > > Where time or `time_zone` parts may be omitted. > > Example: > > ```lua > > datetime = require `datetime` > > d = datetime.parse(`1970-01-01`) > d = datetime.parse(`1970-01-01T00:00:00Z`) > d = datetime.parse(`1970-01-01T02:00:00+02:00`) > ``` > > `parse_date()` � parse ISO-8601 date literal > -------------------------------------------- > > Parse date string literal, return partial date object which has > precision of up-to date period of time. > > A number of standard ISO-8601 formats supported, plus there are some > relaxed formats which are of frequently use: > > | Basic | Extended | | > |----------|------------|--------------------------| > | 20121224 | 2012-12-24 | Calendar date (ISO 8601) | > | 2012359 | 2012-359 | Ordinal date (ISO 8601) | > | 2012W521 | 2012-W52-1 | Week date (ISO 8601) | > | 2012Q485 | 2012-Q4-85 | Quarter date | > > `parse_time()` � parse ISO-8601 time literal > -------------------------------------------- > > Parse time string literal, return partial date/time object, which > defines time period inside of single date. > > A number of standard ISO-8601 formats supported, plus there are some > relaxed formats which are of frequently use: > > | Basic | Extended | > |-------------------|---------------------| > | T12 | N/A | > | T1230 | T12:30 | > | T123045 | T12:30:45 | > | T123045.123456789 | T12:30:45.123456789 | > | T123045,123456789 | T12:30:45,123456789 | > > The time designator T may be omitted. > > `parse_zone()` � parse ISO-8601 time zone > ----------------------------------------- > > Parse time-zone string literal, return partial date/time object, which > defines timezone offset in minutes sing GMT. > > A number of standard ISO-8601 formats supported, plus there are some > relaxed formats which are of frequently use: > > | Basic | Extended | > |-------|----------| > | Z | N/A | > | �hh | N/A | > | �hhmm | �hh:mm | > > `tostring()` � convert datetime object to string > ------------------------------------------------ > > Return string representation (probably compact if there are some parts > missing) of a date-time objects passed > > `now()` � return current date/time > ---------------------------------- > > `now()` returns local date and time object. It will use local time-zone > and nanosecond precision. > > `strftime()` � convert date object to string using format > --------------------------------------------------------- > > `strftime()` is the FFI wrapper around strftime() function in LIBC. It > supports all the same flags which supports strftime() from host OS. > > See > > for more details. > > `asctime()` � convert date object to string using asctime predefined format > --------------------------------------------------------------------------- > > `asctime()` is the FFI wrapper over `asctime_r()` from a host libc. asctime > returns string in the form `"Sun Sep 16 01:03:52 1973\\n\\0"` > > > > `ctime()` � convert local time to string using ctime() predefined format > ------------------------------------------------------------------------ > > `ctime()` is the FFI wrapper over `ctime_r()` in the host libc. ctime > returns string in the form `"Sun Sep 16 01:03:52 1973\\n\\0"` > > > > The difference of `ctime()` and `asctime()` is that former is returning > local time zone formatted, while the latter will deal with GMT. > > Examples: > > ``` > tarantool> date = require 'datetime' > --- > ... > tarantool> T = date.now() > --- > ... > tarantool> T > --- > - 2021-07-14T01:36:48.554105+03:00 > ... > tarantool> date.asctime(T) > --- > - 'Tue Jul 13 22:36:48 2021 > ' > ... > tarantool> date.ctime(T) > --- > - 'Wed Jul 14 01:36:48 2021 > ' > ... > ``` > > Date attribute accessors > ------------------------ > > | | | > |----------------|-----------------------------------------------------------------| > | `timestamp` | Calculate timestamp with seconds and nanoseconds parts combined | > | `nanoseconds` | Number of nanoseconds in time part | > | `microseconds` | Number of microseconds in time part | > | `milliseconds` | Number of milliseconds in time part | > | `seconds` | Alias to timestamp | > | `minutes` | Number of minutes in time part | > | `hours` | Number of hours in time part | > | `days` | Number of days in time part | > > ``` > tarantool> d = date{year = 1970, month = 1, day = 1, hour = 0, minute = 10, second=10} > tarantool> d.secs > --- > - 610 > ... > tarantool> d.nsec > --- > - 0 > ... > tarantool> d.offset > --- > - 0 > ... > tarantool> d.nanoseconds > --- > - 610000000000 > ... > tarantool> d.milliseconds > --- > - 610000 > ... > tarantool> d.hours > --- > - 0.16944444444444 > ... > tarantool> d.minutes > --- > - 10.166666666667 > ... > ``` > > Date arithmetic > --------------- > > TBD > > > https://github.com/tarantool/tarantool/issues/5941 > https://github.com/tarantool/tarantool/issues/5946 > https://github.com/tarantool/tarantool/tree/tsafin/gh-5941-datetime-V2 > > > > Timur Safin (13): > build: add Christian Hansen c-dt to the build > lua: built-in module datetime > test: datetime test > test: datetime string formatting > box: add messagepack support for datetime > lua: positive/negative cases in datetime test > lua: asctime and strfime fixed > box, lua: renamed t_datetime_tz structure to datetime_t > lua: calculated attributes for date > lua: tostring formatization in datetime.lua > test: allow relaxed date format without tz > lua: initial time duration support > lua: complete time duration support > > .gitmodules | 3 + > CMakeLists.txt | 8 + > cmake/BuildCDT.cmake | 6 + > src/CMakeLists.txt | 4 + > src/box/field_def.c | 34 +- > src/box/field_def.h | 1 + > src/box/msgpack.c | 7 +- > src/box/tuple_compare.cc | 24 + > src/exports.h | 26 + > src/lib/core/CMakeLists.txt | 4 +- > src/lib/core/datetime.h | 96 ++++ > src/lib/core/mp_datetime.c | 232 ++++++++ > src/lib/core/mp_extension_types.h | 1 + > src/lib/mpstream/mpstream.c | 11 + > src/lib/mpstream/mpstream.h | 4 + > src/lua/datetime.c | 70 +++ > src/lua/datetime.h | 53 ++ > src/lua/datetime.lua | 868 ++++++++++++++++++++++++++++++ > src/lua/init.c | 6 +- > src/lua/msgpack.c | 12 + > src/lua/msgpackffi.lua | 8 + > src/lua/serializer.c | 4 + > src/lua/serializer.h | 2 + > src/lua/utils.c | 1 - > test/app-tap/datetime.test.lua | 266 +++++++++ > test/unit/CMakeLists.txt | 2 + > test/unit/datetime.c | 220 ++++++++ > test/unit/datetime.result | 358 ++++++++++++ > third_party/c-dt | 1 + > third_party/lua-cjson/lua_cjson.c | 8 + > third_party/lua-yaml/lyaml.cc | 6 +- > 31 files changed, 2326 insertions(+), 20 deletions(-) > create mode 100644 cmake/BuildCDT.cmake > create mode 100644 src/lib/core/datetime.h > create mode 100644 src/lib/core/mp_datetime.c > create mode 100644 src/lua/datetime.c > create mode 100644 src/lua/datetime.h > create mode 100644 src/lua/datetime.lua > create mode 100755 test/app-tap/datetime.test.lua > create mode 100644 test/unit/datetime.c > create mode 100644 test/unit/datetime.result > create mode 160000 third_party/c-dt >