Tarantool development patches archive
 help / color / mirror / Atom feed
From: Safin Timur via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Serge Petrenko <sergepetrenko@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v5 6/8] lua, datetime: time intervals support
Date: Wed, 18 Aug 2021 02:44:11 +0300	[thread overview]
Message-ID: <e337edaa-2fae-4d14-021a-88703d9fd069@tarantool.org> (raw)
In-Reply-To: <317cdf9b-c307-e8f0-5232-ea99c4d9087f@tarantool.org>


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

  reply	other threads:[~2021-08-17 23:44 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-15 23:59 [Tarantool-patches] [PATCH v5 0/8] Initial datetime implementation Timur Safin via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 1/8] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches
2021-08-17 12:15   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:24     ` Safin Timur via Tarantool-patches
2021-08-18  8:56       ` Serge Petrenko via Tarantool-patches
2021-08-17 15:50   ` Vladimir Davydov via Tarantool-patches
2021-08-18 10:04     ` Safin Timur via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 2/8] lua: built-in module datetime Timur Safin via Tarantool-patches
2021-08-17 12:15   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:30     ` Safin Timur via Tarantool-patches
2021-08-18  8:56       ` Serge Petrenko via Tarantool-patches
2021-08-17 16:52   ` Vladimir Davydov via Tarantool-patches
2021-08-17 19:16     ` Vladimir Davydov via Tarantool-patches
2021-08-18 13:38       ` Safin Timur via Tarantool-patches
2021-08-18 10:03     ` Safin Timur via Tarantool-patches
2021-08-18 10:06       ` Safin Timur via Tarantool-patches
2021-08-18 11:45       ` Vladimir Davydov via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 3/8] lua, datetime: display datetime Timur Safin via Tarantool-patches
2021-08-17 12:15   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:32     ` Safin Timur via Tarantool-patches
2021-08-17 17:06   ` Vladimir Davydov via Tarantool-patches
2021-08-18 14:10     ` Safin Timur via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 4/8] box, datetime: messagepack support for datetime Timur Safin via Tarantool-patches
2021-08-16  0:20   ` Safin Timur via Tarantool-patches
2021-08-17 12:15     ` Serge Petrenko via Tarantool-patches
2021-08-17 12:16   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:42     ` Safin Timur via Tarantool-patches
2021-08-18  9:01       ` Serge Petrenko via Tarantool-patches
2021-08-17 18:36   ` Vladimir Davydov via Tarantool-patches
2021-08-18 14:27     ` Safin Timur via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 5/8] box, datetime: datetime comparison for indices Timur Safin via Tarantool-patches
2021-08-17 12:16   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:43     ` Safin Timur via Tarantool-patches
2021-08-18  9:03       ` Serge Petrenko via Tarantool-patches
2021-08-17 19:05   ` Vladimir Davydov via Tarantool-patches
2021-08-18 17:18     ` Safin Timur via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 6/8] lua, datetime: time intervals support Timur Safin via Tarantool-patches
2021-08-17 12:16   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:44     ` Safin Timur via Tarantool-patches [this message]
2021-08-17 18:52   ` Vladimir Davydov via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 7/8] datetime: perf test for datetime parser Timur Safin via Tarantool-patches
2021-08-17 19:13   ` Vladimir Davydov via Tarantool-patches
2021-08-15 23:59 ` [Tarantool-patches] [PATCH v5 8/8] datetime: changelog for datetime module Timur Safin via Tarantool-patches
2021-08-17 12:16   ` Serge Petrenko via Tarantool-patches
2021-08-17 23:44     ` Safin Timur via Tarantool-patches
2021-08-18  9:04       ` Serge Petrenko via Tarantool-patches
2021-08-17 12:15 ` [Tarantool-patches] [PATCH v5 0/8] Initial datetime implementation Serge Petrenko via Tarantool-patches
     [not found] ` <20210818082222.mofgheciutpipelz@esperanza>
2021-08-18  8:25   ` Vladimir Davydov via Tarantool-patches
2021-08-18 13:24     ` Safin Timur via Tarantool-patches
2021-08-18 14:22       ` Vladimir Davydov via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e337edaa-2fae-4d14-021a-88703d9fd069@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=sergepetrenko@tarantool.org \
    --cc=tsafin@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v5 6/8] lua, datetime: time intervals support' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox