From: Timur Safin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [RFC PATCH 08/13] box, lua: renamed t_datetime_tz structure to datetime_t Date: Thu, 15 Jul 2021 11:18:14 +0300 [thread overview] Message-ID: <e289a77b456ae64d40ab6727f07089eba0c8f631.1626335241.git.tsafin@tarantool.org> (raw) In-Reply-To: <cover.1626335241.git.tsafin@tarantool.org> --- src/box/tuple_compare.cc | 4 ++-- src/lib/core/datetime.h | 22 +++++++++++----------- src/lib/core/mp_datetime.c | 24 ++++++++++++------------ src/lib/mpstream/mpstream.c | 2 +- src/lib/mpstream/mpstream.h | 4 ++-- src/lua/datetime.c | 6 +++--- src/lua/datetime.h | 2 +- src/lua/datetime.lua | 2 +- src/lua/msgpack.c | 2 +- src/lua/msgpackffi.lua | 6 +++--- src/lua/serializer.c | 2 +- src/lua/serializer.h | 2 +- src/lua/utils.c | 1 - test/unit/datetime.c | 21 ++++++++++----------- 14 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/box/tuple_compare.cc b/src/box/tuple_compare.cc index 39c9dd6e9..28814428c 100644 --- a/src/box/tuple_compare.cc +++ b/src/box/tuple_compare.cc @@ -401,8 +401,8 @@ mp_compare_uuid(const char *field_a, const char *field_b) static int mp_compare_datetime(const char *lhs, const char *rhs) { - t_datetime_tz lhs_dt, rhs_dt; - t_datetime_tz *ret; + datetime_t lhs_dt, rhs_dt; + datetime_t *ret; ret = mp_decode_datetime(&lhs, &lhs_dt); assert(ret != NULL); ret = mp_decode_datetime(&rhs, &rhs_dt); diff --git a/src/lib/core/datetime.h b/src/lib/core/datetime.h index bd23f33a3..b289b0486 100644 --- a/src/lib/core/datetime.h +++ b/src/lib/core/datetime.h @@ -47,7 +47,7 @@ extern "C" { /** * datetime structure consisting of: */ -struct t_datetime_tz { +struct datetime_t { int secs; ///< seconds since epoch int nsec; ///< nanoseconds if any int offset; ///< offset in minutes from GMT @@ -62,27 +62,27 @@ struct t_datetime_duration { }; int -datetime_compare(const struct t_datetime_tz * lhs, - const struct t_datetime_tz * rhs); +datetime_compare(const struct datetime_t * lhs, + const struct datetime_t * rhs); -struct t_datetime_tz * -datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date); +struct datetime_t * +datetime_unpack(const char **data, uint32_t len, struct datetime_t *date); char * -datetime_pack(char *data, const struct t_datetime_tz *date); +datetime_pack(char *data, const struct datetime_t *date); uint32_t -mp_sizeof_datetime(const struct t_datetime_tz *date); +mp_sizeof_datetime(const struct datetime_t *date); -struct t_datetime_tz * -mp_decode_datetime(const char **data, struct t_datetime_tz *date); +struct datetime_t * +mp_decode_datetime(const char **data, struct datetime_t *date); char * -mp_encode_datetime(char *data, const struct t_datetime_tz *date); +mp_encode_datetime(char *data, const struct datetime_t *date); int -datetime_to_string(const struct t_datetime_tz * date, char *buf, uint32_t len); +datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len); int mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len); diff --git a/src/lib/core/mp_datetime.c b/src/lib/core/mp_datetime.c index 2cf3fd79b..ad18f00c8 100644 --- a/src/lib/core/mp_datetime.c +++ b/src/lib/core/mp_datetime.c @@ -63,7 +63,7 @@ mp_decode_Xint(const char **data) } uint32_t -mp_sizeof_datetime(const struct t_datetime_tz *date) +mp_sizeof_datetime(const struct datetime_t *date) { uint32_t sz = mp_sizeof_Xint(date->secs); @@ -77,8 +77,8 @@ mp_sizeof_datetime(const struct t_datetime_tz *date) return sz; } -struct t_datetime_tz * -datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date) +struct datetime_t * +datetime_unpack(const char **data, uint32_t len, struct datetime_t *date) { const char * svp = *data; @@ -102,8 +102,8 @@ datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date) return date; } -struct t_datetime_tz * -mp_decode_datetime(const char **data, struct t_datetime_tz *date) +struct datetime_t * +mp_decode_datetime(const char **data, struct datetime_t *date) { if (mp_typeof(**data) != MP_EXT) return NULL; @@ -118,7 +118,7 @@ mp_decode_datetime(const char **data, struct t_datetime_tz *date) } char * -datetime_pack(char *data, const struct t_datetime_tz *date) +datetime_pack(char *data, const struct datetime_t *date) { data = mp_encode_Xint(data, date->secs); if (date->nsec != 0 || date->offset != 0) @@ -130,7 +130,7 @@ datetime_pack(char *data, const struct t_datetime_tz *date) } char * -mp_encode_datetime(char *data, const struct t_datetime_tz *date) +mp_encode_datetime(char *data, const struct datetime_t *date) { uint32_t len = mp_sizeof_datetime(date); @@ -140,7 +140,7 @@ mp_encode_datetime(char *data, const struct t_datetime_tz *date) } int -datetime_to_string(const struct t_datetime_tz * date, char *buf, uint32_t len) +datetime_to_string(const struct datetime_t * date, char *buf, uint32_t len) { char * src = buf; int offset = date->offset; @@ -191,7 +191,7 @@ datetime_to_string(const struct t_datetime_tz * date, char *buf, uint32_t len) int mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len) { - struct t_datetime_tz date = {0}; + struct datetime_t date = {0}; if (datetime_unpack(data, len, &date) == NULL) return -1; @@ -202,7 +202,7 @@ mp_snprint_datetime(char *buf, int size, const char **data, uint32_t len) int mp_fprint_datetime(FILE *file, const char **data, uint32_t len) { - struct t_datetime_tz date; + struct datetime_t date; if (datetime_unpack(data, len, &date) == NULL) return -1; @@ -220,8 +220,8 @@ adjusted_secs(int secs, int offset) } int -datetime_compare(const struct t_datetime_tz * lhs, - const struct t_datetime_tz * rhs) +datetime_compare(const struct datetime_t * lhs, + const struct datetime_t * rhs) { int result = COMPARE_RESULT(adjusted_secs(lhs->secs, lhs->offset), adjusted_secs(rhs->secs, rhs->offset)); diff --git a/src/lib/mpstream/mpstream.c b/src/lib/mpstream/mpstream.c index 8c92b4049..1077e3b19 100644 --- a/src/lib/mpstream/mpstream.c +++ b/src/lib/mpstream/mpstream.c @@ -210,7 +210,7 @@ mpstream_encode_uuid(struct mpstream *stream, const struct tt_uuid *uuid) } void -mpstream_encode_datetime(struct mpstream *stream, const struct t_datetime_tz *val) +mpstream_encode_datetime(struct mpstream *stream, const struct datetime_t *val) { char *data = mpstream_reserve(stream, mp_sizeof_datetime(val)); if (data == NULL) diff --git a/src/lib/mpstream/mpstream.h b/src/lib/mpstream/mpstream.h index 39e8fd956..540e9a666 100644 --- a/src/lib/mpstream/mpstream.h +++ b/src/lib/mpstream/mpstream.h @@ -39,7 +39,7 @@ extern "C" { #endif /* defined(__cplusplus) */ struct tt_uuid; -struct t_datetime_tz; +struct datetime_t; /** * Ask the allocator to reserve at least size bytes. It can reserve @@ -147,7 +147,7 @@ void mpstream_encode_uuid(struct mpstream *stream, const struct tt_uuid *uuid); void -mpstream_encode_datetime(struct mpstream *stream, const struct t_datetime_tz *dt); +mpstream_encode_datetime(struct mpstream *stream, const struct datetime_t *dt); /** Copies n bytes from memory area src to stream. */ void diff --git a/src/lua/datetime.c b/src/lua/datetime.c index 215cb89fb..a4f9915e0 100644 --- a/src/lua/datetime.c +++ b/src/lua/datetime.c @@ -39,7 +39,7 @@ uint32_t CTID_DATETIME_TZ = 0; uint32_t CTID_DURATION = 0; -struct t_datetime_tz * +struct datetime_t * luaL_pushdatetime(struct lua_State *L) { return luaL_pushcdata(L, CTID_DATETIME_TZ); @@ -48,14 +48,14 @@ luaL_pushdatetime(struct lua_State *L) void tarantool_lua_datetime_init(struct lua_State *L) { - int rc = luaL_cdef(L, "struct t_datetime_tz {" + int rc = luaL_cdef(L, "struct datetime_t {" "int secs;" "int nsec;" "int offset;" "};"); assert(rc == 0); (void) rc; - CTID_DATETIME_TZ = luaL_ctypeid(L, "struct t_datetime_tz"); + CTID_DATETIME_TZ = luaL_ctypeid(L, "struct datetime_t"); assert(CTID_DATETIME_TZ != 0); diff --git a/src/lua/datetime.h b/src/lua/datetime.h index 38ba53561..cee96ca06 100644 --- a/src/lua/datetime.h +++ b/src/lua/datetime.h @@ -42,7 +42,7 @@ extern uint32_t CTID_DURATION; struct lua_State; -struct t_datetime_tz* +struct datetime_t* luaL_pushdatetime(struct lua_State *L); void diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua index efd953de9..086c97697 100644 --- a/src/lua/datetime.lua +++ b/src/lua/datetime.lua @@ -150,7 +150,7 @@ local NANOS_PER_SEC = 1000000000LL local DT_EPOCH_1970_OFFSET = 719163LL -local datetime_t = ffi.typeof('struct t_datetime_tz') +local datetime_t = ffi.typeof('struct datetime_t') local duration_t = ffi.typeof('struct t_datetime_duration') local function duration_new() diff --git a/src/lua/msgpack.c b/src/lua/msgpack.c index dd2c41056..0a4ba8129 100644 --- a/src/lua/msgpack.c +++ b/src/lua/msgpack.c @@ -339,7 +339,7 @@ luamp_decode(struct lua_State *L, struct luaL_serializer *cfg, } case MP_DATETIME: { - struct t_datetime_tz * date = luaL_pushdatetime(L); + struct datetime_t * date = luaL_pushdatetime(L); date = datetime_unpack(data, len, date); if (date == NULL) goto ext_decode_err; diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index 2613cf216..271be857a 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -36,8 +36,8 @@ decimal_t * decimal_unpack(const char **data, uint32_t len, decimal_t *dec); struct tt_uuid * uuid_unpack(const char **data, uint32_t len, struct tt_uuid *uuid); -struct t_datetime_tz * -datetime_unpack(const char **data, uint32_t len, struct t_datetime_tz *date); +struct datetime_t * +datetime_unpack(const char **data, uint32_t len, struct datetime_t *date); ]]) local strict_alignment = (jit.arch == 'arm') @@ -517,7 +517,7 @@ local ext_decoder = { end, -- MP_DATETIME [4] = function(data, len) - local dt = ffi.new("struct t_datetime_tz") + local dt = ffi.new("struct datetime_t") builtin.datetime_unpack(data, len, dt) return dt end, diff --git a/src/lua/serializer.c b/src/lua/serializer.c index 55120a725..160d6fe7e 100644 --- a/src/lua/serializer.c +++ b/src/lua/serializer.c @@ -543,7 +543,7 @@ luaL_tofield(struct lua_State *L, struct luaL_serializer *cfg, field->uuidval = (struct tt_uuid *) cdata; } else if (cd->ctypeid == CTID_DATETIME_TZ) { field->ext_type = MP_DATETIME; - field->dateval = (struct t_datetime_tz *) cdata; + field->dateval = (struct datetime_t *) cdata; } else if (cd->ctypeid == CTID_CONST_STRUCT_ERROR_REF && opts != NULL && opts->error_marshaling_enabled) { diff --git a/src/lua/serializer.h b/src/lua/serializer.h index ec62c723f..52e51d279 100644 --- a/src/lua/serializer.h +++ b/src/lua/serializer.h @@ -224,7 +224,7 @@ struct luaL_field { uint32_t size; decimal_t *decval; struct tt_uuid *uuidval; - struct t_datetime_tz *dateval; + struct datetime_t *dateval; }; enum mp_type type; /* subtypes of MP_EXT */ diff --git a/src/lua/utils.c b/src/lua/utils.c index 34cec0eed..5ec0ce135 100644 --- a/src/lua/utils.c +++ b/src/lua/utils.c @@ -232,7 +232,6 @@ luaL_setcdatagc(struct lua_State *L, int idx) lua_pop(L, 1); } - /** * A helper to register a single type metatable. */ diff --git a/test/unit/datetime.c b/test/unit/datetime.c index f74ac139d..7e0229758 100644 --- a/test/unit/datetime.c +++ b/test/unit/datetime.c @@ -129,36 +129,35 @@ parse_datetime(const char *str, size_t len, int64_t *sp, int64_t *np, // avoid introducing external datetime.h dependency // - just copy paste it for today #define SECS_PER_DAY 86400 -#define NANOS_PER_SEC 1000000000 #define DT_EPOCH_1970_OFFSET 719163 -struct t_datetime_tz { - int64_t sec; +struct datetime_t { + int64_t secs; int64_t nsec; int64_t offset; }; static int -local_rd(const struct t_datetime_tz * dt) { - return (int)(dt->sec / SECS_PER_DAY) + DT_EPOCH_1970_OFFSET; +local_rd(const struct datetime_t * dt) { + return (int)(dt->secs / SECS_PER_DAY) + DT_EPOCH_1970_OFFSET; } static int -local_dt(const struct t_datetime_tz * dt) { +local_dt(const struct datetime_t * dt) { return dt_from_rdn(local_rd(dt)); } struct tm* -datetime_to_tm(struct t_datetime_tz * dt) +datetime_to_tm(struct datetime_t * dt) { static struct tm tm; memset(&tm, 0, sizeof(tm)); dt_to_struct_tm(local_dt(dt), &tm); - int seconds_of_day = dt->sec % 86400; + int seconds_of_day = 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; @@ -189,14 +188,14 @@ static void datetime_test(void) // check that stringized literal produces the same date // time fields static char buff[40]; - struct t_datetime_tz dt = {secs, nanosecs, ofs}; + struct datetime_t dt = {secs, nanosecs, ofs}; // datetime_to_tm returns time in GMT zone struct tm * p_tm = datetime_to_tm(&dt); size_t len = strftime(buff, sizeof buff, "%F %T%z", p_tm); ok(len > 0, "strftime"); - rc = parse_datetime(buff, len, &dt.sec, &dt.nsec, &dt.offset); + rc = parse_datetime(buff, len, &dt.secs, &dt.nsec, &dt.offset); is(rc, 0, "correct parse_datetime return value for '%s'", buff); - is(secs, dt.sec, + is(secs, dt.secs, "reversible seconds via strftime for '%s", buff); } } -- 2.29.2
next prev parent reply other threads:[~2021-07-15 8:22 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-15 8:18 [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 01/13] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 02/13] lua: built-in module datetime Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 03/13] test: datetime test Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 04/13] test: datetime string formatting Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 05/13] box: add messagepack support for datetime Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 06/13] lua: positive/negative cases in datetime test Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 07/13] lua: asctime and strfime fixed Timur Safin via Tarantool-patches 2021-07-15 8:18 ` Timur Safin via Tarantool-patches [this message] 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 09/13] lua: calculated attributes for date Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 10/13] lua: tostring formatization in datetime.lua Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 11/13] test: allow relaxed date format without tz Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 12/13] lua: initial time duration support Timur Safin via Tarantool-patches 2021-07-15 8:18 ` [Tarantool-patches] [RFC PATCH 13/13] lua: complete " Timur Safin via Tarantool-patches 2021-07-15 16:56 ` [Tarantool-patches] [RFC PATCH 00/13] Initial datetime support Oleg Babin via Tarantool-patches 2021-07-15 23:03 ` Timur Safin via Tarantool-patches 2021-07-16 6:58 ` Oleg Babin via Tarantool-patches 2021-07-22 10:01 ` Igor Munkin via Tarantool-patches 2021-07-22 12:54 ` Timur Safin 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=e289a77b456ae64d40ab6727f07089eba0c8f631.1626335241.git.tsafin@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=tsafin@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [RFC PATCH 08/13] box, lua: renamed t_datetime_tz structure to datetime_t' \ /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