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 49EDD6EC41; Tue, 17 Aug 2021 15:18:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 49EDD6EC41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629202721; bh=E1e9J+4xRw9LZEi3oT3QbEQ7hNrsxdcUfBvSSIWHd6s=; 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=vGbNMFUUWXhCe7J2bI/XJB1bzxTKsbGjaLfSsqlq67nm/SO1D1XeT1eLdLsd2yixS svxnGGV6Dvonc64AFB3CPKUy9R5ujSKJVtGNadJHGiipLcSJ1r+zhz5ESFZBv1sMKE 80XroTgUFgwfjnxB5l+zt6Jb9qhsT/uiHMHvy+Q0= Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (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 A4EFC6EC41 for ; Tue, 17 Aug 2021 15:16:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A4EFC6EC41 Received: by smtp37.i.mail.ru with esmtpa (envelope-from ) id 1mFy14-0003Vy-93; Tue, 17 Aug 2021 15:16:26 +0300 To: Timur Safin References: <58bf0cbee84cccbe619c225aafa7d471a4c920ca.1629071531.git.tsafin@tarantool.org> Message-ID: <317cdf9b-c307-e8f0-5232-ea99c4d9087f@tarantool.org> Date: Tue, 17 Aug 2021 15:16:25 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <58bf0cbee84cccbe619c225aafa7d471a4c920ca.1629071531.git.tsafin@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD906AB4890CDABF0C5CB76CEE71D3E4007182A05F53808504096038C0AD7D5C8D2642D4AD3CBCF54E20418E528012F2786ED4F3EA31291D386 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7BC08626EA5717D14EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637FBDDB35DE4C816078638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D883244CFCB59DD4EFF1D6B9327B7B564B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD1828451B159A507268D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B67ECBC18655D52CDF089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A55D383A69D562D2E3E24E8F3EDE8035F582BB635E530562DBD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7567C209D01CC1E34B410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34B0359B88B232A0C603BBE125482F49B9257C40229549AFEB469993A74546CCE79BEA4B3D5A40ACEF1D7E09C32AA3244C5F79997F73A40FF816C2B8AF8AB9DDB66C2483212766842283B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojuRQ/H5n28trm79mEdLD/Xw== X-Mailru-Sender: 3B9A0136629DC9125D61937A2360A446C2819093F73A8E04822FCFFBFC6FB5A9D114087478469B2E424AE0EB1F3D1D21E2978F233C3FAE6EE63DB1732555E4A8EE80603BA4A5B0BC112434F685709FCF0DA7A0AF5A3A8387 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: Serge Petrenko via Tarantool-patches Reply-To: Serge Petrenko Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 16.08.2021 02:59, Timur Safin via Tarantool-patches пишет: > * created few entry points (months(N), years(N), days(N), etc.) > for easier datetime arithmetic; > * additions/subtractions of years/months use `dt_add_years()` > and `dt_add_months()` from 3rd party c-dt library; > * also there are `:add{}` and `:sub{}` methods in datetime > object to add or substract more complex intervals; > * introduced `is_datetime()` and `is_interval()` helpers for checking > of validity of passed arguments; > * human-readable stringization implemented for interval objects. > > Note, that additions/subtractions completed for all _reasonable_ > combinations of values of date and interval types; > > Time + Interval => Time > Interval + Time => Time > Time - Time => Interval > Time - Interval => Time > Interval + Interval => Interval > Interval - Interval => Interval > > Part of #5941 > --- > extra/exports | 3 + > src/lua/datetime.lua | 349 ++++++++++++++++++++++++++++++++- > test/app-tap/datetime.test.lua | 159 ++++++++++++++- > 3 files changed, 506 insertions(+), 5 deletions(-) > > diff --git a/extra/exports b/extra/exports > index c34a5c2b5..421dda51f 100644 > --- a/extra/exports > +++ b/extra/exports > @@ -157,6 +157,9 @@ datetime_to_string > datetime_unpack > decimal_from_string > decimal_unpack > +tnt_dt_add_years > +tnt_dt_add_quarters > +tnt_dt_add_months > tnt_dt_dow > tnt_dt_from_rdn > tnt_dt_from_struct_tm > 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. > // 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. -- Serge Petrenko