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 37A447F626; Fri, 6 Aug 2021 20:24:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 37A447F626 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628270661; bh=zeUwgH+qtACvg31ZJOMQmESh7mw/Uta1R2Cywg8lCLs=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Ur0VhruixCmM/8RtAfl54AxhEI7SXegiYcM7ibNw+OI7WFyi/gMJtLjSu8tDlXNNk CP1aLeR9n3c8K7C4WevEpsS4XYEIfMbBoh4xvNCqTk5V+41+2KeLtrNuL2N4tsE714 6OZHZ5fikLKDrZnfBlLRNBKI2PJREW8p6Do6Pt7M= Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 827CF7F625 for ; Fri, 6 Aug 2021 20:24:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 827CF7F625 Received: by smtp53.i.mail.ru with esmtpa (envelope-from ) id 1mC3Zy-0000Ru-EE; Fri, 06 Aug 2021 20:24:18 +0300 To: Oleg Babin , Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org References: <449cb4c7-c738-ed07-8517-61b663ad9f79@tarantool.org> <0931c9db-bd8e-0687-2c96-73fac1aeff7e@tarantool.org> <331a5d04-d756-fac0-fa07-cac594fa7ed8@tarantool.org> Message-ID: <65a5628f-17db-c7c3-a0e5-8e81eb98da30@tarantool.org> Date: Fri, 6 Aug 2021 20:24:17 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD910164DC12A5633065676A9727AC27C74182A05F538085040F7C61527A3B676EE9783445C8B8FE92E81975C454F531342826E4BFA7EFF9386 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE732F68F8AF5E5BA59EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006375FE8AD9F0D2764EB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8D8256EB15B159969E343A4A92056AE7C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EED76C6ED7039589DE040F9FF01DFDA4A84AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3C30C415A873EAD8ABA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE732FCE54C4D9A645443847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A59645A1CF2FB584C5103BD6328D9B48E3F14638911DA9CD33D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C53592357E805773E49DB1190034D5DFB809524BF575E8F150F236402DC8CF35EFF26266CC9E0BA91D7E09C32AA3244C6B9B77A3C8EF4E2FFC0CA1E21A16BD7FF522A1CF68F4BE05FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojFhlvmGwdUwQexZjgTUPXWA== X-Mailru-Sender: B5B6A6EBBD94DAD8AF988FF52E735F3B4268D021C06FF66BE50CE1D7C0F19B67F8580613C06DCA7A5C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v3 2/9] lua: built-in module datetime 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 Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On 06.08.2021 16:00, Safin Timur via Tarantool-patches wrote: > > On 06.08.2021 4:30, Oleg Babin wrote: >> >> On 06.08.2021 03:23, Safin Timur wrote: >>> >>> i.e. whenever we see not datetime or interva value datetime_cmp >>> return nil, and all comparisons always return false. Please give me >>> know if that's incorrect scenario and we should raise exception. This >>> was the way Oleg Bain has requested it to behave. (return false for >>> bogus data) >>> >> Hi! Seems you understood me wrong. It was only about equal comparison. >> >> ``` >> >> tarantool> uuid.new() == newproxy() >> --- >> - false >> ... >> >> tarantool> uuid.new() > newproxy() >> --- >> - error: '[string "return require(''uuid'').new() > newproxy()"]:1: >> incorrect value >>      to convert to uuid as 1 argument' >> ... >> >> ``` >> >> >> However, currently I see that decimal have a bit different behaviour >> and raises always: >> >> ``` >> >> tarantool> decimal.new(1) == newproxy() >> --- >> - error: '[string "return decimal.new(1) == newproxy()"]:1: expected >> decimal, number >>      or string as 2 argument' >> ... >> >> tarantool> decimal.new(1) > newproxy() >> --- >> - error: '[string "return decimal.new(1) > newproxy()"]:1: expected >> decimal, number >>      or string as 1 argument' >> ... >> >> ``` >> >> >> IMO, the first case is better because we can check that two lua >> built-in types >> >> are equal but can't compare them. >> >> ``` >> >> tarantool> {} == 'string' >> --- >> - false >> ... >> >> tarantool> {} > 'string' >> --- >> - error: '[string "return {} > ''string''"]:1: attempt to compare >> string with table' >> ... >> >> ``` >> >> > > Now, that looks more or less consistent, will do it such! > > ``` > tarantool> date = require 'datetime' > --- > ... > > tarantool> T = date('1970-01-01') > --- > ... > > tarantool> T == false > --- > - false > ... > > tarantool> T == true > --- > - false > ... > > tarantool> T < false > --- > - error: '[string "return T < false"]:1: incompatible types for comparison' > ... > > tarantool> T <= 'string' > --- > - error: '[string "return T <= ''string''"]:1: incompatible types for > comparison' > ... > ``` > > Patch is simple though > ============================================================== > diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua > index 0bc86c9f3..509a2981f 100644 > --- a/src/lua/datetime.lua > +++ b/src/lua/datetime.lua > @@ -245,12 +245,12 @@ end > >  local function datetime_lt(lhs, rhs) >      local rc = datetime_cmp(lhs, rhs) > -    return rc ~= nil and rc < 0 or false > +    return rc ~= nil and rc < 0 or error('incompatible types for > comparison', 2) >  end > >  local function datetime_le(lhs, rhs) >      local rc = datetime_cmp(lhs, rhs) > -    return rc ~= nil and rc <= 0 or false > +    return rc ~= nil and rc <= 0 or  error('incompatible types for > comparison', 2) >  end > >  local function datetime_serialize(self) > ============================================================== Well, actually that was incorrect version (it was raising error if we have compatible types but comparison failed), condition should look different, but idea you saw correct: ============================================================ local function datetime_eq(lhs, rhs) local rc = datetime_cmp(lhs, rhs) return rc ~= nil and rc == 0 end local function datetime_lt(lhs, rhs) local rc = datetime_cmp(lhs, rhs) return rc == nil and error('incompatible types for comparison', 2) or rc < 0 end local function datetime_le(lhs, rhs) local rc = datetime_cmp(lhs, rhs) return rc == nil and error('incompatible types for comparison', 2) or rc <= 0 end ============================================================ > > Do we want to use that approach here? > > Thanks, > Timur