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 389A06EC40; Wed, 18 Aug 2021 02:44:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 389A06EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629243865; bh=OC4e2rbsI+3SzwZOjJqggWjMBpk0N6riaPbwQK56xNo=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=hn1Nyz0gaPjrPH9DSQQfjCwOL40EVWhFkd+No0eFlaLvWiQg8SIi+pc3o602y5XAp QaGMuKj6mP8RsWmDf8qC+nuRp9KmPmMxQH+GXFm5l6qKbc40mv0qbGwXGrR+bchaDo /tmYSvZTnGjrCFnk3urrQDn46lefglux8FF5N5EM= Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [217.69.128.39]) (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 32AEE6EC40 for ; Wed, 18 Aug 2021 02:44:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 32AEE6EC40 Received: by smtp59.i.mail.ru with esmtpa (envelope-from ) id 1mG8ko-0002YP-Js; Wed, 18 Aug 2021 02:44:23 +0300 To: Serge Petrenko References: <58bf0cbee84cccbe619c225aafa7d471a4c920ca.1629071531.git.tsafin@tarantool.org> <317cdf9b-c307-e8f0-5232-ea99c4d9087f@tarantool.org> Message-ID: Date: Wed, 18 Aug 2021 02:44:11 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <317cdf9b-c307-e8f0-5232-ea99c4d9087f@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9BCE6B93DE0C6C3914462CDB1732D383C182A05F538085040B46590628E39CA0E4B45F65460ED1603967ACF655FD12C2C0955399E84A852CD X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70D278D70F8433719EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748D05F5E01EE6C998638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82E3304697CD8BA263EED9F4ABC6BA14C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BF1175FABE1C0F9B6A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FC7AABBC3B12AC6BCD3AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F790063740BA071C1C7EF6BBD81D268191BDAD3D698AB9A7B718F8C4D1B931868CE1C5781A620F70A64A45A98AA50765F79006372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89FB26E97DCB74E62525E1C53F199C2BB95B5C8C57E37DE458BEDA766A37F9254B7 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79D0B18DC6AC13D9A1C615406044A17E8CA X-C1DE0DAB: 0D63561A33F958A5D2F5814BCEC3D4763719802AF96A16E01F78AE5C9F41DF6FD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA757E10A58996CBD514410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340B06C327CE4A70E8FBBD3DCB65DD8C759FC492DF703435C44BB9C5D999BDC0B109427112C41B84411D7E09C32AA3244C7DA6C6B1DEE7F1A885C9A46E9E7F898BB018FE5BB746DCD183B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojuRQ/H5n28trIzDwQ2nNdtw== X-Mailru-Sender: B5B6A6EBBD94DAD8C64AB2DDE1BF89F455A63FB8D6CDD7D0A6A14C9EFB6BD5D31F70F67D4A942BC45C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 6/8] lua, datetime: time intervals 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: Safin Timur via Tarantool-patches Reply-To: Safin Timur Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 17.08.2021 15:16, Serge Petrenko wrote: > >> diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua >> index 4d946f194..5fd0565ac 100644 >> --- a/src/lua/datetime.lua >> +++ b/src/lua/datetime.lua >> @@ -24,6 +24,17 @@ ffi.cdef [[ >>       int      tnt_dt_rdn          (dt_t dt); >> +    // dt_arithmetic.h >> +    typedef enum { >> +        DT_EXCESS, >> +        DT_LIMIT, >> +        DT_SNAP >> +    } dt_adjust_t; >> + >> +    dt_t    tnt_dt_add_years        (dt_t dt, int delta, dt_adjust_t >> adjust); >> +    dt_t    tnt_dt_add_quarters     (dt_t dt, int delta, dt_adjust_t >> adjust); >> +    dt_t    tnt_dt_add_months       (dt_t dt, int delta, dt_adjust_t >> adjust); >> + > > > Same about comments inside ffi.cdef. Better avoid them. > > Please, split the cdef into reasonable blocks with > comments (when you need them) > between the blocks. I've split this code into several ffi.cdef blocks, so at the moment the header of a module looks like this ----------------------------------------------------------------- --[[ `c-dt` library functions handles properly both positive and negative `dt` values, where `dt` is a number of dates since Rata Die date (0001-01-01). For better compactness of our typical data in MessagePack stream we shift root of our time to the Unix Epoch date (1970-01-01), thus our 0 is actually dt = 719163. So here is a simple formula how convert our epoch-based seconds to dt values dt = (secs / 86400) + 719163 Where 719163 is an offset of Unix Epoch (1970-01-01) since Rata Die (0001-01-01) in dates. ]] -- dt_core.h definitions ffi.cdef [[ typedef int dt_t; dt_t tnt_dt_from_rdn (int n); dt_t tnt_dt_from_ymd (int y, int m, int d); int tnt_dt_rdn (dt_t dt); ]] -- dt_arithmetic.h definitions ffi.cdef [[ typedef enum { DT_EXCESS, DT_LIMIT, DT_SNAP } dt_adjust_t; dt_t tnt_dt_add_years (dt_t dt, int delta, dt_adjust_t adjust); dt_t tnt_dt_add_quarters (dt_t dt, int delta, dt_adjust_t adjust); dt_t tnt_dt_add_months (dt_t dt, int delta, dt_adjust_t adjust); ]] -- dt_parse_iso.h definitions ffi.cdef [[ size_t tnt_dt_parse_iso_date (const char *str, size_t len, dt_t *dt); size_t tnt_dt_parse_iso_time (const char *str, size_t len, int *sod, int *nsec); size_t tnt_dt_parse_iso_zone_lenient (const char *str, size_t len, int *offset); ]] -- Tarantool functions - datetime.c ffi.cdef [[ int datetime_to_string(const struct datetime * date, char *buf, int len); char * datetime_asctime(const struct datetime *date, char *buf); char * datetime_ctime(const struct datetime *date, char *buf); size_t datetime_strftime(const struct datetime *date, const char *fmt, char *buf, uint32_t len); void datetime_now(struct datetime * now); ]] ----------------------------------------------------------------- > > >>       // dt_parse_iso.h >>       size_t tnt_dt_parse_iso_date          (const char *str, size_t >> len, dt_t *dt); >>       size_t tnt_dt_parse_iso_time          (const char *str, size_t >> len, int *sod, int *nsec); >> @@ -50,8 +61,10 @@ ffi.cdef [[ >>   local builtin = ffi.C >>   local math_modf = math.modf >> +local math_floor = math.floor >>   local SECS_PER_DAY     = 86400 >> +local NANOS_PER_SEC    = 1000000000 >>   -- c-dt/dt_config.h >> >> > > Everything else looks fine. > Thanks, Timur